[英]VBA for opening and editing multiple Powerpoint files
I have a folder with over 200 Powerpoint files and I have been have been struggling with a Macro that opens each of these files, edits them, saves them and closes them in a loop. 我有一个包含200多个Powerpoint文件的文件夹,而且我一直在努力使用宏来打开每个文件,对其进行编辑,保存并在循环中将其关闭。 I have managed to create code for the editing part, however I can't manage to create a code that picks each of the files in the folder.
我已经为编辑部分创建了代码,但是我无法创建用于选择文件夹中每个文件的代码。 Using
"*.pptx"
doesn't seem to work and writing code with a specific filename for each of these files is very inefficient. 使用
"*.pptx"
似乎不起作用,并且为每个文件使用特定文件名编写代码的效率非常低。
Does anyone have a solution to this? 有人对此有解决方案吗?
Sub SaveNotesText()
Dim oPres As Presentation
Dim oSlides As Slides
Dim oSlide As Slide
Dim oShapes As Shapes
Dim oSh As Shape
Dim NotesText As String
Dim FileNum As Integer
Dim PathSep As String
#If Mac Then
PathSep = ":"
#Else
PathSep = "\"
#End If
Set oPres = ActivePresentation
Set oSlides = oPres.Slides
For Each oSlide In oSlides
NotesText = NotesText & "Slide " & oSlide.SlideIndex & vbCrLf
Set oShapes = oSlide.NotesPage.Shapes
For Each oSh In oShapes
If oSh.HasTextFrame Then
If oSh.TextFrame.HasText Then
NotesText = NotesText & oSh.TextFrame.TextRange.Text
End If
End If
Next oSh
NotesText = NotesText & vbCrLf
Next oSlide
FileNum = FreeFile
Open oPres.Path & PathSep & "NotesText.TXT" For Output As FileNum
Print #FileNum, NotesText
Close FileNum
End Sub
http://www.pptfaq.com/FAQ00274.htm http://www.pptfaq.com/FAQ00274.htm
You can use Dir to loop through all the "#.ppt#" files in a folder, ie 您可以使用Dir循环浏览文件夹中的所有“#.ppt#”文件,即
Public Sub DoFiles()
Dim strFileName As String
Dim strFolderName As String
Dim PP As Presentation
'set default directory here if needed
strFolderName = "C:\temp"
strFileName = Dir(strFolderName & "\*.ppt*")
Do While Len(strFileName) > 0
Set PP = Presentations.Open(strFolderName & "\" & strFileName)
'your code
PP.Close
strFileName = Dir
Loop
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.