下面我有一些代码可以找到并替换某个单词。但是,我对VBA的了解有限,所以我不知道如何通过文件夹中的多个Powerpoint文件循环此代码并保存它们。另外它只需要写在第一张纸上的文字,我不知道这是怎么回事?
Sub DemoFindReplace()
Dim sld As Slide
Set sld = ActivePresentation.Slides(1)
Dim shp As Shape
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "TEST", "REPLACE")
End If
End If
Next shp
End Sub
答案 0 :(得分:0)
您提出的问题并不是很清楚,但如果您想循环浏览大量文件,则以下代码会有所帮助:
Dim MyFile, MyPath, MyName As String
' Returns "WIN.INI" if it exists.
MyFile = Dir("C:\WINDOWS\WIN.INI")
' Returns filename with specified extension. If more than one *.INI
' file exists, the first file found is returned.
MyFile = Dir("C:\WINDOWS\*.INI")
' Call Dir again without arguments to return the next *.INI file in the
' same directory.
MyFile = Dir()
' Return first *.TXT file, including files with a set hidden attribute.
MyFile = Dir("*.TXT", vbHidden)
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
' Display entry only if it's a directory.
MsgBox(MyName)
End If
MyName = Dir() ' Get next entry.
Loop
来源:https://msdn.microsoft.com/en-us/library/dk008ty4(v=vs.90).aspx