【发布时间】:2015-06-11 23:41:09
【问题描述】:
我有 700 多张幻灯片,分布在大约 30 个 pptx 文件中。许多文件的部分文本设置为西班牙语拼写检查。为了更改每张幻灯片中每个文本的拼写检查语言,我一直在互联网上搜索可以做到这一点的 VBS 脚本。不幸的是,对我来说还没有一个完整的解决方案:出现了各种错误,并不是每个脚本都包含母版和注释页面等。所以我写了自己的,以解决我自己的问题。这里是:
Option Explicit
Const msoFalse = 0
Const msoTrue = -1
Const msoLanguageIDEnglishUS = 1033
Const msoGroup = 6
Dim intShapeCount, intTextCount
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objStartingFolder : Set objStartingFolder = objFSO.GetFolder(".\")
IterateContainingItems objStartingFolder
Sub IterateContainingItems(objCurrentFolder)
Dim colFiles : Set colFiles = objCurrentFolder.Files
Dim objCurrentFile
For Each objCurrentFile in colFiles
ReportInfo(objCurrentFile)
Next
Dim colFolders : Set colFolders = objCurrentFolder.SubFolders
Dim objNextFolder
For Each objNextFolder in colFolders
IterateContainingItems objNextFolder
Next
End Sub
Sub ReportInfo(objCurrentFile)
Dim strPathToFile
strPathToFile = objFSO.GetAbsolutePathName(objCurrentFile.Path)
Wscript.Echo strPathToFile
If objFSO.GetExtensionName(strPathToFile) = "pptx" Then
Dim objPowerpointApp, objPresentations, objPresentation, objSlides, intSlideCount
set objPowerpointApp = CreateObject("Powerpoint.Application")
set objPresentations = objPowerpointApp.Presentations
Set objPresentation = objPresentations.Open(strPathToFile, 0, 0, 0)
Set objSlides = objPresentation.Slides
intSlideCount = objSlides.Count
ResetLanguage objPresentation
Wscript.Echo vbTab & "Slides: " & intSlideCount
Wscript.Echo vbTab & "Shapes: " & intShapeCount
Wscript.Echo vbTab & "Text: " & intTextCount
objPresentation.Close
objPowerpointApp.Quit
Else
Wscript.Echo vbTab & "N/A"
End If
End Sub
Sub ResetLanguage(objCurrentPresentation)
'change shapes from presentation-wide masters
Dim objShape
intShapeCount = 0
intTextCount = 0
If objCurrentPresentation.HasHandoutMaster Then
For Each objShape in objCurrentPresentation.HandoutMaster.Shapes
ChangeLanguage objShape
Next
End If
If objCurrentPresentation.HasNotesMaster Then
For Each objShape in objCurrentPresentation.NotesMaster.Shapes
ChangeLanguage objShape
Next
End If
If objCurrentPresentation.HasTitleMaster = msoTrue Then
For Each objShape in objCurrentPresentation.TitleMaster.Shapes
ChangeLanguage objShape
Next
End If
'change shapes from each design's master
Dim tempDesign
For Each tempDesign in objCurrentPresentation.Designs
For Each objShape in tempDesign.SlideMaster.Shapes
ChangeLanguage objShape
Next
Next
'change shapes from each slide
Dim tempSlide
For Each tempSlide in objCurrentPresentation.Slides
For Each objShape in tempSlide.Shapes
ChangeLanguage objShape
Next
If tempSlide.hasNotesPage Then
For Each objShape in tempSlide.NotesPage.Shapes
ChangeLanguage objShape
Next
End If
Next
End Sub
Sub ChangeLanguage(objShape)
If objShape.Type = msoGroup Then
Dim objShapeGroup : Set objShapeGroup = objShape.Ungroup
Dim objShapeChild
For Each objShapeChild in objShapeGroup
ChangeLanguage objShapeChild
Next
Else
intShapeCount = intShapeCount + 1
If objShape.HasTextFrame Then
intTextCount = intTextCount + 1
If objShape.TextFrame.TextRange.Length = 0 Then
objShape.TextFrame.TextRange.Text = "[PLACEHOLDER_TEXT_TO_DELETE]"
End If
objShape.TextFrame.TextRange.LanguageID = msoLanguageIDEnglishUS
If objShape.TextFrame.TextRange.Text = "[PLACEHOLDER_TEXT_TO_DELETE]" Then
objShape.TextFrame.TextRange.Text = ""
End If
End If
End If
End Sub
这几乎完美。据我所知,所有幻灯片和母版都已正确检查,但演讲者的笔记仍然以西班牙语检查不正确。我只在网上找到了可以访问我已经做过的“Notes Page”的解决方案。我认为演讲者备注与备注页面不同。
仔细观察后发现,脚本并没有改变任何的拼写检查语言。该脚本运行没有错误,并表明它找到了所有文本框,所以现在我更加迷茫了。
我如何使用 VBS 更改这些演示文稿的演讲者备注(不是备注页面)的语言?
【问题讨论】:
标签: vbscript powerpoint spell-checking