vba - 从 Word VBA 编辑 PowerPoint 演示文稿页脚
问题描述
我在 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
推荐阅读
- javascript - SAP Cloud SDK JavaScript:具有位置 ID 的 onPremise 目的地没有 CSRF 令牌
- r - 光栅中的反应式表达
- angular - 如何在 NativeScript 中对表单进行单元测试?
- laravel - 如何在循环中包含连接数据
- php - 将数据从表单发送到一页并转到另一页
- php - 在 Laravel 中存储从 OAuth 接收到的数组
- c# - 调用 HttpClient 并从分页请求中获得相同的结果 - 是我还是服务?
- python - 从 3D numpy.MaskedArray 中删除切片
- animation - 颤动如何在同一页面上的小部件之间制作类似英雄的动画
- python - 为什么 2**1024 工作,而 2**(2048/2) 导致溢出错误?