我希望這個特定的代碼可以在文件夾中的多個PPT文件上運行。但是,如果它打開Powerpoint文件,運行下面的代碼,保存並打開下一個代碼會更好。歡迎任何建議!我已經通過這個網站上的代碼,但似乎無法使它適應我的代碼如下(如這一個Loop through files in a folder using VBA?)如何將此VBA應用於文件夾中的多個PPT文件
環不未遂
標誌
Sub LoopThroughFiles()
Dim MyObj As Object, MySource As Object, file As Variant
file = Dir("c:\testfolder\")
While (file <> "")
If InStr(file, "test") > 0 Then
MsgBox "found " & file
Exit Sub
End If
file = Dir
Wend
End Sub
現有代碼
Option Explicit
' Selects the shape that support text which is closest to the top of the slide
' Written by Jamie Garroch of YOUpresent Ltd (http://youpresent.co.uk)
Sub SelectHigestTextShape()
Dim oSld As Slide
Dim oShp As Shape, oShpTop As Shape
Dim sShpTop As Single
On Error Resume Next
Set oSld = ActiveWindow.View.Slide
If Err Then Exit Sub
On Error GoTo 0
' Set the top to the bottom of the slide
sShpTop = ActivePresentation.PageSetup.SlideHeight
' Check each shape on the slide is positioned above the stored position
' Shapes not supporting text and placeholders are ignored
For Each oShp In oSld.Shapes
If oShp.Top < sShpTop And oShp.HasTextFrame And Not oShp.Type = msoPlaceholder Then
sShpTop = oShp.Top
Set oShpTop = oShp
End If
Next
' Select the topmost shape
If Not oShpTop Is Nothing Then oShpTop.Select msoTrue
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
' Clean up
Set oSld = Nothing
Set oShp = Nothing
Set oShpTop = Nothing
End Sub
你試過什麼循環? –
Sub LoopThroughFiles() Dim MyObj As Object,MySource As Object,file As Variant file = Dir(「c:\ testfolder \」) While(file <>「」) If InStr(file,「test」) > 0,則 MSGBOX「發現」和文件 退出小組 結束如果 文件= DIR 蜿蜒 結束小組 我已將此添加到代碼,但它刪除,因爲它沒有工作:( – Probs
它看起來像使用文件系統對象,你有沒有參考加載?它看起來不正確,沒有GetFolder在那裏像你從 –