![]() |
Tipp 0032
|
Symbolleiste erstellen
|
 |
|
Autor/Einsender: Datum: |
|
Angie 29.01.2006 (Update) |
|
Entwicklungsumgebung: |
|
Word 2000 |
|
|
In diesem Beispiel wird zunächst eine neue Symbolleiste erstellt und dieser dann drei Schaltflächen hinzugefügt.
|
Den beiden Schaltflächen 'Sprache Deutsch' und 'Sprache Englisch' wird ein OnAction-Makro zugewiesen, das bei Klick auf den entsprechenden Button
ausgeführt wird. Hier wird nicht nur die Sprache der Formatvorlage 'Standard' zu Deutsch bzw. Englisch geändert, sondern auch gleichzeitig
der bereits vorhandene Text im Hauptteil des Dokuments entsprechend umgestellt.
|
Bei der dritten Schaltfläche 'Rechtschreibkennzeichnung aus-/einblenden' handelt es sich um den Word-Befehl 'Rechtschreibfehler ausblenden' und entspricht der
Einstellung im Menü Extras /Optionen...
|
|
|
Option Explicit
Private Const mc_CBAR_NAME As String = "VB-fun-Symbolleiste"
Private Const mc_BTN_TAG As String = "MY_BUTTON"
Public Sub CreateCommandBar()
Dim objCBar As Office.CommandBar
Dim objCBBtn As Office.CommandBarButton
Application.CustomizationContext = ThisDocument
On Error Resume Next
Set objCBar = Application.CommandBars(mc_CBAR_NAME)
On Error GoTo 0
If Not objCBar Is Nothing Then
Call ToggleCommandBarButtons
Exit Sub
End If
On Error GoTo err_CreateCommandBar
Set objCBar = Application.CommandBars.Add( _
Name:=mc_CBAR_NAME, Temporary:=True)
With objCBar
.Visible = True
.Position = msoBarTop
.Protection = msoBarNoCustomize + msoBarNoChangeVisible
End With
Set objCBBtn = objCBar.Controls.Add(Type:=msoControlButton)
With objCBBtn
.Style = msoButtonIconAndCaption
.Caption = "Sprache &Deutsch"
.Tag = mc_BTN_TAG & "1"
.TooltipText = "Spracheinstellung zu Deutsch ändern"
.FaceId = 790
.BeginGroup = True
.OnAction = "ToggleLanguageOptions"
End With
Set objCBBtn = objCBar.Controls.Add(Type:=msoControlButton)
With objCBBtn
.Style = msoButtonIconAndCaption
.Caption = "Sprache &Englisch (GB)"
.Tag = mc_BTN_TAG & "2"
.TooltipText = "Spracheinstellung zu Englisch ändern"
.FaceId = 790
.BeginGroup = True
.OnAction = "ToggleLanguageOptions"
End With
Set objCBBtn = objCBar.Controls.Add _
(Type:=msoControlButton, ID:=3217)
With objCBBtn
.Style = msoButtonCaption
.Caption = "&Rechtschreibfehler aus-/einblenden"
.Tag = mc_BTN_TAG & "3"
.BeginGroup = True
End With
Call ToggleCommandBarButtons
exit_Sub:
On Error Resume Next
Set objCBBtn = Nothing
Set objCBar = Nothing
ThisDocument.Saved = True
On Error GoTo 0
Exit Sub
err_CreateCommandBar:
MsgBox "Fehler #: " & Err.Number & vbCrLf & _
Err.Description, vbOKOnly + vbCritical
Resume exit_Sub
End Sub
Sub ToggleCommandBarButtons()
Dim objCBBtn_German As Office.CommandBarButton
Dim objCBBtn_English As Office.CommandBarButton
On Error Resume Next
Set objCBBtn_German = Application.CommandBars.FindControl( _
Tag:=mc_BTN_TAG & "1")
Set objCBBtn_English = Application.CommandBars.FindControl( _
Tag:=mc_BTN_TAG & "2")
If Err.Number = 0 Then
Select Case ActiveDocument.Styles("Standard").LanguageID
Case wdGerman
objCBBtn_German.State = msoButtonDown
objCBBtn_English.State = msoButtonUp
Case wdEnglishUK
objCBBtn_German.State = msoButtonUp
objCBBtn_English.State = msoButtonDown
Case Else
End Select
End If
ThisDocument.Saved = True
On Error GoTo 0
End Sub
Sub ToggleLanguageOptions()
Const c_BOOKMARK As String = "DummyBookmark"
If Not Application.CommandBars.ActionControl Is Nothing Then
On Error Resume Next
Application.ScreenUpdating = False
ActiveDocument.Bookmarks.Add Name:=c_BOOKMARK, _
Range:=Selection.Range
Select Case Application.CommandBars.ActionControl.Tag
Case mc_BTN_TAG & "1"
ActiveDocument.Styles("Standard").LanguageID = wdGerman
ActiveDocument.Content.LanguageID = wdGerman
Case mc_BTN_TAG & "2"
ActiveDocument.Styles("Standard").LanguageID = wdEnglishUK
ActiveDocument.Content.LanguageID = wdEnglishUK
Case Else
End Select
With ActiveDocument.Bookmarks(c_BOOKMARK)
.Select
.Delete
End With
Call ToggleCommandBarButtons
Application.ScreenUpdating = True
On Error GoTo 0
End If
End Sub
|
|
|
|
|
|
Im Download befindet sich eine *.bas-Datei, die in Word im VB-Editor importiert werden kann.
|
|
Windows-Version |
95 |
 |
|
98/SE |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
Word-Version |
95 |
 |
|
97 |
 |
|
2000 |
 |
|
2002
(XP) |
 |
|
2003 |
 |
|
2007 |
 |
|
2010 |
 |
|
|
|
Download (2,6 kB)
|
Downloads bisher: [ 1437 ]
|
|
|