我创建了一个带有自定义幻灯片布局的PowerPoint。我希望能够使用Excel VBA使用这些自定义布局之一创建新幻灯片,但我无法弄清楚正确的语法。
这是我目前的代码:
Sub runPPT()
Application.ScreenUpdating = False
Dim wb As Workbook
Set wb = ThisWorkbook
Dim ws As Worksheet
Set ws = wb.Sheets("SG2")
Dim pptName As String
Dim ppt As Object
Dim myPres As Object
Dim slds As Object
Dim sld As Object
MsgBox ("Please choose PowerPoint to open.")
pptName = openDialog()
Set ppt = CreateObject("PowerPoint.Application")
Set myPres = ppt.Presentations.Open(pptName)
Set slds = myPres.Slides
'This is where I want to add my custom layout
'My layouts all have similar names like "Gate 2 Main" if that helps
Set sld = slds.AddSlides(Slides.Count + 1, ActivePresentation.SlideMaster.CustomLayouts(1))
Application.ScreenUpdating = True
End Sub
Private Function openDialog()
Dim fd As Office.FileDialog
Dim txtFileName As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Please select the file."
' Clear out the current filters, and add our own.
.Filters.Clear
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
txtFileName = .SelectedItems(1) 'replace txtFileName with your textbox
End If
End With
openDialog = txtFileName
End Function
答案 0 :(得分:1)
我可以通过将代码更改为以下内容来解决我的问题:
import ctypes
try:
libc = ctypes.CDLL('libc.so.6')
res_init = getattr(libc, '__res_init')
res_init(None)
except:
pass