2016-09-29 5 views
0

unten Ich habe einen Code, der ein bestimmtes Wort findet und ersetzt. Mein Wissen über VBA ist jedoch begrenzt, so dass ich nicht weiß, wie ich diesen Code durch mehrere Powerpoint-Dateien in einem Ordner führen und speichern kann. Es braucht auch nur Wörter auf dem ersten Blatt, ich weiß nicht, was los ist?Schleife VBA durch mehrere Dateien

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

Bitte beachten dass der Code die Formatierung aller Textfelder unterbricht, es sei denn, sie enthalten keine internen Unterschiede in Schriftart, Fettdruck usw. – Jbjstam

Antwort

0

Es ist nicht wirklich klar, wetzen Sie fragen, aber wenn Sie durch eine Reihe von Dateien Schleife wollen die folgenden Code helfen:

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 

Quelle: https://msdn.microsoft.com/en-us/library/dk008ty4(v=vs.90).aspx

Verwandte Themen