我正在尝试根据下周四的日期保存具有不同FileName的powerpoint文件。这意味着,如果我将文件保存在18.10.2016(相应于星期二),而不是文件的名称是20/10/2016(相应于下一个星期四)。
这就是我写的,但似乎是假的:
Sub SaveAll()
Dim prs As Presentation
Dim Todate As Date
On Error Resume Next
For Each prs In Presentations
Todate = DateValue(Now)
oldWeekDay = Weekday(Todate)
Select Case oldWeekDay
Case 1
prs.saveAs "C:\Users\Moez\Desktop\Macro_Project\Todate + 4.pptm"
Case 2
prs.saveAs "C:\Users\Moez\Desktop\Macro_Project\Todate + 3.pptm"
Case 3
prs.saveAs "C:\Users\Moez\Desktop\Macro_Project\Todate + 2.pptm"
Case 4
prs.saveAs "C:\Users\Moez\Desktop\Macro_Project\Todate + 1.pptm"
Case 5
prs.saveAs "C:\Users\Moez\Desktop\Macro_Project\Todate.pptm"
Case 6
prs.saveAs "C:\Users\Moez\Desktop\Macro_Project\Todate + 6.pptm"
Case 7
prs.saveAs "C:\Users\Moez\Desktop\Macro_Project\Todate + 5.pptm"
End Select
Next prs
End Sub
感谢您的帮助
答案 0 :(得分:1)
要将日期添加到日期,请使用DateAdd
。您可以计算添加未确定(7 + numberOfDayYouWant - numberOfDayYouHave) Mod 7
Dim nextThursday As Date
Dim strDate As String
Dim Todate As Date
Todate = Date 'the "Date" function returns the date portion of "Now"
'find the next thursday
nextThursday = DateAdd("d", (12 - Weekday(Todate)) Mod 7, Todate)
'make a string
strDate = Format(nextThursday, "yyyy-mm-dd") 'edit format as you wish
'now save the presentation, e.g.
'Set prs = someting
prs.SaveAs "C:\Users\Moez\Desktop\Macro_Project\" & strDate & ".pptm"
由您决定不以同一名称保存演示文稿