Редактирование PowerPoint презентации нижнего колонтитула из Word VBA - PullRequest
1 голос
/ 06 февраля 2020

У меня есть код в 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

1 Ответ

0 голосов
/ 08 февраля 2020

Чтобы изменить настройку в объекте HeaderFooter, необходимо убедиться, что объект «видим», иначе он не существует. Так, например

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