|
有人帮我吗?没人,只好用老办法了。Private Sub Workbook_open()
Dim a As String
Dim b As String
Dim c As String ' 创建一个临时变量,以防出现生成的文件名为0号
Dim RptName1 As String
Dim RptName2 As String
Dim mypath As String
Dim Done As String '生成上交报表的日期与时间
Dim MyToday As String
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
RptName1 = Month(Now) & "月" & Day(Now) - 1 & "号"
RptName2 = Month(Now) & "月" & Day(Now) - 2 & "号"
Done = Now()
MyToday = Month(Now()) & "月" & Day(Now()) & "号" '将生成日期标记于生成的报表名称
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 a = 0 Then '即判断当前日期是否为月初第一天,如果是则提醒打开上个月的报表
MsgBox "本月是月初的第一天,请检查打开的生产报表为上个月的,请仔细检查生成的报表是否正确!谢谢"
a = Day(DateSerial(Year(Now), Month(Now), 0))
c = Month(Now) - 1 '创建一个临时变量,以防出现生成的文件名为0号
Sheets(Array(a, "黄小姐")).Copy
ActiveWorkbook.SaveAs Filename:= _
mypath & "\" & c & "月" & a & "号" & "的生产报表(上交):创建于" & MyToday & ".xls", FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
MsgBox "自动生成上交的工作表为:" & c & "月" & a & "号的,请注意检查!!!!完成于" & Done
Else
If Weekday(Now) = 2 Then '判断是否为星期一
b = a - 1
Sheets(Array(a, b, "黄小姐")).Copy
ActiveWorkbook.SaveAs Filename:= _
mypath & "\" & RptName1 & "和" & RptName2 & "的生产报表(上交):创建于" & MyToday & ".xls", FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
MsgBox "自动生成上交的工作表为:" & Month(Now) & "月" & a & "号的与" & b & "号的,请注意检查!!!!完成于" & Done
Else
Sheets(Array(a, "黄小姐")).Copy
ActiveWorkbook.SaveAs Filename:= _
mypath & "\" & RptName1 & "的生产报表(上交):创建于" & MyToday & ".xls", FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
MsgBox "自动生成上交的工作表为:" & Month(Now) & "月" & a & "号的,请注意检查!!!!完成于" & Done
End If
End If
End If
End Sub |
|