簡體   English   中英

從 Word VBA 編輯 PowerPoint 演示文稿頁腳

[英]Editing PowerPoint presentation footer from Word VBA

我在 Word 中有代碼可以復制文件夾,將文件夾粘貼到類似區域,然后將文件重命名為當前周數。

在文件夾內的文件中,有一個 PowerPoint 演示文稿。 演示文稿有一個帶文本的頁腳,我想在 Word 代碼中更新該文本。 我嘗試了很多不同的東西。

這是我當前的代碼:

Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Message = Format(Date, "ww", vbSunday)

'if message < 10 then it will be KW0 + WEEK NUMBER. IF IT IS BIGGER THAN TEN, IT WILL BE KW + NUMBER.

If Message < 10 Then
    FromPath = "directory here"
    ToPath = "directory here"
End If

If Message >= 10 Then
    FromPath = "directory here"
    ToPath = "directory here"
End If

If Right(FromPath, 1) = "\" Then
    FromPath = Left(FromPath, Len(FromPath) - 1)
End If

If Right(ToPath, 1) = "\" Then
    ToPath = Left(ToPath, Len(ToPath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(FromPath) = False Then
    MsgBox FromPath & " doesn't exist. Please speak to me."
    Exit Sub
End If

FSO.CopyFolder Source:=FromPath, Destination:=ToPath

If Message < 10 Then
    Name "directory here" _
    As "directory here"

    Name "directory here" _
    As "directory here"
End If

If Message >= 10 Then
    Name "directory here" _
    As "directory here"

    Name "directory here" _
    As "directory here"
End If

以上工作。

繼續打開演示文稿如下:(注意:演示文稿打開,但我無法在 VBA 代碼中編輯頁腳。)

Dim opptapp As PowerPoint.Application
Dim oPPTFile As PowerPoint.Presentation
Dim oPPTSlide As PowerPoint.Slide
Set opptapp = CreateObject("PowerPoint.Application")
opptapp.Visible = msoTrue

If Message < 10 Then
    Set oPPTFile = opptapp.Presentations.Open(FileName:="directory here")
End If

If Message >= 10 Then
    Set oPPTFile = opptapp.Presentations.Open(FileName:="directory here")
End If

ActivePresentation.Slides(1).HeadersFooters.Footer.Text = "Volcano Coffee"

MsgBox "The pack for next week has now been generated!"

End Sub

為了更改HeaderFooter對象中的設置,必須確保該對象“可見”,否則它不存在。 所以,例如

With oPPTFile.Slides(1).HeadersFooters.Footer
   .Visible = True
   .Text = "Volcano Coffee"
End With

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM