2,462
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Dim pptApp
Dim NewPres,MyPres1,MyPres2,MyPres3 '创建对象,用于存放PPT
Dim Fso,oFile1,oFile2,oFile3
Dim MyPath1,MyPath2,MyPath3,SavedPath
Dim i
Set pptApp = CreateObject("PowerPoint.Application")'创建并返回对PPT Automation对象的引用
Set Fso = CreateObject("Scripting.FileSystemObject")
MyPath1 = BrowseForFolder & "\" '对话框中选定的当前文件夹路径
'这里尝试采用不遍历的方法获得所选文件,失败了~~~~遍历方法可以,但是只能在文件夹下只有一个ppt的时候使用
'使用GetOpenFilename可以实现获取单个PPT的目的吗??
'set oFile1= Fso.GetFolder(MyPath1).Files
'Set MyPres1 = GetObject(MyPath1 & oFile1.Name)
For Each oFile1 In Fso.GetFolder(MyPath1).Files
If InStr(oFile1.Name, ".ppt") >0 And InStr(oFile1.Name, "~$")=0 Then
Set MyPres1 = GetObject(MyPath1 & oFile1.Name)
End if
next
MyPath2 = BrowseForFolder & "\"
'set oFile2= Fso.GetFolder(MyPath2).Files
'Set MyPres2 = GetObject(MyPath2 & oFile2.Name)
For Each oFile2 In Fso.GetFolder(MyPath2).Files
If InStr(oFile2.Name, ".ppt") >0 And InStr(oFile2.Name, "~$")=0 Then
Set MyPres2 = GetObject(MyPath2 & oFile2.Name)
End if
next
MyPath3 = BrowseForFolder & "\"
'set oFile3= Fso.GetFolder(MyPath3).Files
'set MyPres3 = GetObject(MyPath3 & oFile3.Name)
For Each oFile3 In Fso.GetFolder(MyPath3).Files
If InStr(oFile3.Name, ".ppt") >0 And InStr(oFile3.Name, "~$")=0 Then
Set MyPres3 = GetObject(MyPath3 & oFile3.Name)
End if
next
SavedPath = BrowseForFolderD & "\" '对话框中选定的当前文件夹路径,能否改成选定单个ppt?????
'以下代码通过复制粘贴实现PPT三合一,但是不能保留原始PPT风格模板,方法比较笨,大神如有更好的方法欢迎分享
Set NewPres = pptApp.Presentations.Add(0) '创建新演示文稿,新演示文稿不显示
If MyPres1.Slides.Count=MyPres2.Slides.Count and MyPres2.Slides.Count=MyPres3.Slides.Count then
For i = 1 To MyPres1.Slides.Count
MyPres1.Slides(i).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
MyPres2.Slides(i).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
MyPres3.Slides(i).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
Next
NewPres.SaveAs(SavedPath & "Merged PPT")
NewPres.Close
Set NewPres = Nothing
else if MyPres1.Slides.Count=MyPres2.Slides.Count and MyPres2.Slides.Count>MyPres3.Slides.Count then
For i = 1 To MyPres1.Slides.Count-1
MyPres1.Slides(i).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
MyPres2.Slides(i).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
MyPres3.Slides(i).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
Next
MyPres1.Slides(MyPres1.Slides.Count).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
MyPres2.Slides(MyPres1.Slides.Count).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
NewPres.SaveAs(SavedPath & "Merged PPT")
NewPres.Close
Set NewPres = Nothing
else
For i = 1 To MyPres1.Slides.Count-1
MyPres1.Slides(i).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
MyPres2.Slides(i).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
MyPres3.Slides(i).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
Next
MyPres1.Slides(MyPres1.Slides.Count).Copy
NewPres.Slides.Paste (NewPres.Slides.Count + 1)
NewPres.SaveAs(SavedPath & "Merged PPT")
NewPres.Close
Set NewPres = Nothing
End if
Set Fso = Nothing
Set pptApp = Nothing
MsgBox "结束" '以下能否将shell BrowseForFolder这个打开文件夹的命令改成打开文件的命令?
'___________________________________________________________________________________
Function BrowseForFolder() '定义对话框格式
Dim FD
Set FD = CreateObject("Shell.Application").BrowseForFolder(0, "请以左-中-右屏顺序选择PPT所在文件夹:", 0, 0) '定义对话框格式
If Not FD Is Nothing Then'如果选择文件夹则返回文件夹路径
BrowseForFolder = FD.Self.Path & ""
Else
MsgBox "已取消"
wscript.quit
Exit Function
End if
End Function
'___________________________________________________________________________________
Function BrowseForFolderD() '定义对话框格式
Dim FDD
Set FDD = CreateObject("Shell.Application").BrowseForFolder(0, "请选择存放合并PPT的文件夹:", 0, 0) '定义对话框格式
If Not FDD Is Nothing Then'如果选择文件夹则返回文件夹路径
BrowseForFolderD = FDD.Self.Path & ""
MsgBox "开始合并", vbOKOnly+vbInformation
Else
MsgBox "已取消"
wscript.quit
Exit Function
End if
End Function
End if
Option Explicit
Dim pptApp, FileName
Set pptApp = CreateObject("PowerPoint.Application")
FileName = SelectFile(pptApp)
If(len(FileName))then
MsgBox "选择的文件是:"&FileName, 64
Else
MsgBox "没有选择文件。",64
End If
pptApp.Quit
set pptApp = Nothing
Wscript.Quit
Function SelectFile(objApp)
Dim objDialog
Set objDialog = objApp.FileDialog(3)
objDialog.AllowMultiSelect=False ' 单文件选择
objDialog.Filters.Clear
objDialog.Filters.Add "MS ppt文件(*.ppt, *.pptx)", "*.ppt;*.pptx"
objDialog.Filters.Add "所有文件(*.*)", "*.*"
objApp.Visible = True '必须显示出来才可以
If (objDialog.Show()) Then
SelectFile=objDialog.SelectedItems(1)
Else
SelectFile=""
End If
set objDialog=Nothing
End Function
Option Explicit
Dim pptApp, FileName
Set pptApp = CreateObject("PowerPoint.Application")
FileName = SelectFile(pptApp)
If(len(FileName))then
MsgBox "选择的文件是:"&FileName, 64
Else
MsgBox "没有选择文件。",64
End If
pptApp.Quit
set pptApp = Nothing
Wscript.Quit
Function SelectFile(objApp)
Dim objDialog
Set objDialog = objApp.FileDialog(3)
objDialog.AllowMultiSelect=False ' 单文件选择
objDialog.Filters.Clear
objDialog.Filters.Add "MS ppt文件(*.ppt, *.pptx)", "*.ppt;*.pptx"
objDialog.Filters.Add "所有文件(*.*)", "*.*"
objApp.Visible = True '必须显示出来才可以
If (objDialog.Show()) Then
SelectFile=objDialog.SelectedItems(1)
Else
SelectFile=""
End If
set objDialog=Nothing
End Function