【发布时间】:2025-11-25 17:25:01
【问题描述】:
我正在尝试创建一个带有按钮的工具栏,该按钮会将 PowerPoint 文档中所有形状和文本框的 LanguageID 更改为 EnglishUS。这是为了解决一个问题,即如果有人使用另一种语言(在本例中为法语)对文档进行拼写检查,该语言会嵌入到 .ppt 文件本身中。当另一个用户尝试使用另一种语言(例如英语)对同一区域进行拼写检查时,拼写检查器建议的单词是原始语言。例如,它试图将“指定”一词更正为“指定”,一个法语单词。根据我的阅读,解决此语言问题的唯一方法是使用 VBscript,而在 Powerpoint 中运行 VBscript 而无需将其嵌入 .ppt 并每次都加载该文件的唯一方法是创建一个加载项使用工具栏按钮运行宏,也使用 VBS。下面是我从各种来源获取的代码,当我尝试将它放在一起时,它不起作用(尽管它确实编译了)。如果有人可以看一下,我敢肯定它是一个简单的语法错误或类似的东西,这将是一个巨大的帮助。提前致谢!!
顺便说一句,如果有人知道在 PPT 中运行宏而无需每次都打开某个 PPT 的更简单方法,我很乐意。
现在,脚本:
Sub Auto_Open()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim MyToolbar As String
''# Give the toolbar a name
MyToolbar = "Fix Language"
On Error Resume Next
''# so that it doesn't stop on the next line if the toolbar's already there
''# Create the toolbar; PowerPoint will error if it already exists
Set oToolbar = CommandBars.Add(Name:=MyToolbar, _
Position:=msoBarFloating, Temporary:=True)
If Err.Number <> 0 Then
''# The toolbar's already there, so we have nothing to do
Exit Sub
End If
On Error GoTo ErrorHandler
''# Now add a button to the new toolbar
Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)
''# And set some of the button's properties
With oButton
.DescriptionText = "Fix Language for Spell Check"
''# Tooltip text when mouse if placed over button
.Caption = "Click to Run Script"
''# Text if Text in Icon is chosen
.OnAction = "Button1"
''# Runs the Sub Button1() code when clicked
.Style = msoButtonIcon
''# Button displays as icon, not text or both
.FaceId = 59
End With
''# Repeat the above for as many more buttons as you need to add
''# Be sure to change the .OnAction property at least for each new button
''# You can set the toolbar position and visibility here if you like
''# By default, it'll be visible when created
oToolbar.Top = 150
oToolbar.Left = 150
oToolbar.Visible = True
NormalExit:
Exit Sub ''# so it doesn't go on to run the errorhandler code
ErrorHandler:
''# Just in case there is an error
MsgBox Err.Number & vbCrLf & Err.Description
Resume NormalExit:
End Sub
Sub Button1()
''# This is the code to replace the LanguageID throughout the ppt
Option Explicit
Public Sub ChangeSpellCheckingLanguage()
Dim j As Integer, k As Integer, scount As Integer, fcount As Integer
scount = ActivePresentation.Slides.Count
For j = 1 To scount
fcount = ActivePresentation.Slides(j).Shapes.Count
For k = 1 To fcount
If ActivePresentation.Slides(j).Shapes(k).HasTextFrame Then
ActivePresentation.Slides(j).Shapes(k) _
.TextFrame.TextRange.LanguageID = msoLanguageIDEnglishUS
End If
Next k
Next j
End Sub
End Sub
【问题讨论】:
标签: vbscript powerpoint