Опитвам се да създам лента с инструменти с бутон, който ще промени LanguageID
за всички форми и текстови полета в документ на PowerPoint на EnglishUS. Това е за отстраняване на проблем, при който, ако някой провери правописа на документ, използвайки друг език (в този случай френски), този език се вгражда в самия .ppt файл. Когато друг потребител се опита да провери правописа в същата област, използвайки друг език, например английски, думите, които програмата за проверка на правописа предлага, са на оригиналния език. Например, той се опита да коригира думата „определено“ на „специфично“, френска дума. От това, което прочетох, единственият начин да се коригира този езиков проблем е с VBscript и единственият начин да се стартира VBscript в Powerpoint, без да се вгражда в .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