|
那么这段代码是否还可以进行优化呢?Private Sub Workbook_open()
Dim a As String '将A定义为字符串
Dim mypath As String
Dim myfile As String
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "要现在上交报表吗?点是,将生成上交报表,点否将不生成报表。请在生成后检查!!!谢谢"
Style = vbYesNo + vbInformation + vbDefaultButton1
Title = "请在生成后检查!!!谢谢"
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then
MyString = "Yes"
a = Day(Now) - 1 '定义出需要复制的工作表名
mypath = ThisWorkbook.Path ''获得当前文件存放的位置
=========================================== If Day(Now()) = 1 Then
a = a + 1
Sheets(Array(a, "黄小姐")).Select
Sheets(a).Activate
Sheets(Array(a, "黄小姐")).Copy
ActiveWorkbook.SaveAs Filename:= _
mypath & "\上交报表.xls", FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False==================================================突然又想起代码中还存在着一个问题。那就是你要上交的报表是以今天的日期减去1得到的工作表名称(1-31),假设今天是2005-07-01,a=day(now)-1,则a=0;换句话说,VBA会找不到名称为"0"的工作表。所以建议是提交本日a=day(now)的报表,这样就不会有问题了
==================================================
Else
Sheets(Array(a, "黄小姐")).Select
Sheets(a).Activate
Sheets(Array(a, "黄小姐")).Copy
ActiveWorkbook.SaveAs Filename:= _
mypath & "\上交报表.xls", FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
End If
Else
MyString = "No"
Sheets("黄小姐").Activate
End If
End Sub
|
|