vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Erstellen von dynamischen Kontextmen?s - wann immer Sie sie brauchen!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
CommandBar und CommandBarButton 
Autor: AnyVBUser
Datum: 10.03.11 16:03

Hi,
ich versuch grad mal ne Symbolleiste mit einem Button in der Word-Anwendung zu erstellen.
Als Vorlage nutze ich diese Seite: http://msdn.microsoft.com/en-us/library/aa289518%28v=vs.71%29.aspx
Ich habe die Codes bei mir eingefügt und ggf. angepasst. Es werden bei mir keine Fehler angezeigt und ist kompilierbar.
Fürs Testen benutze ich Word 2003. Nun gut, ich habs getestet aber muss leider sagen dass es bei mir nicht funktioniert. In Word wird überhaupt keine Symbolleiste erstellt und kann auch keine neue Leiste im Kontextmenü (rechte Maustaste auf freie Stelle oben) sehen. Es muss doch funktionieren aber vielleicht kann mir JEMAND helfen?

Private Function AddWordToolbar(ByVal word As Outlook.Application, _
    ByVal toolbarName As String) As Microsoft.Office.Core.CommandBar
 
        Dim toolBar As Microsoft.Office.Core.CommandBar = Nothing
        Try
            ' Create a command bar for the add-in
            toolBar = CType(word.CommandBars.Add(toolbarName, _
                Microsoft.Office.Core.MsoBarPosition.msoBarTop, , True),  _
                Microsoft.Office.Core.CommandBar)
            toolBar.Visible = True
            Return toolBar
        Catch
            ' Add exception handling here.
            Return Nothing
        End Try
    End Function
 
    Private Function MakeANewButton(ByVal commandBar As  _
    Microsoft.Office.Core.CommandBar, ByVal caption As String, _
    ByVal faceID As Integer, ByVal clickHandler As  _
    Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler) _
    As Microsoft.Office.Core.CommandBarButton
        Try
            Dim newButton As Microsoft.Office.Core.CommandBarButton
            newButton = CType(commandBar.Controls.Add( _
                Microsoft.Office.Core.MsoControlType.msoControlButton),  _
                Microsoft.Office.Core.CommandBarButton)
            newButton.Caption = caption
            newButton.FaceId = faceID
            AddHandler newButton.Click, clickHandler
            Return newButton
        Catch ex As System.Exception
            ' Add code here to handle the exception.
            Return Nothing
        End Try
    End Function
 
    Public Sub insertText_Click(ByVal barButton As  _
    Microsoft.Office.Core.CommandBarButton, ByRef someBool As Boolean)
        Dim text As String = ""
        Dim data As System.Windows.Forms.IDataObject = _
        System.Windows.Forms.Clipboard.GetDataObject()
        If data.GetDataPresent(System.Windows.Forms.DataFormats.Text) Then
            text = data.GetData( _
                System.Windows.Forms.DataFormats.Text).ToString()
            If (Not wordApp Is Nothing) Then
                Me.wordApp.ActiveWindow.Selection.InsertBefore(text)
            End If
        End If
    End Sub
 
    Public Sub styleText_Click(ByVal barButton As  _
        Microsoft.Office.Core.CommandBarButton, ByRef someBool As Boolean)
        Dim code As Object = "Code"
        If (Not wordApp Is Nothing) Then
            Me.wordApp.ActiveWindow.Selection.Style = code
        End If
    End Sub
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
  System.EventArgs) Handles MyBase.Load
 
'Dim toolbar As Microsoft.Office.Core.CommandBar
        'Dim wordApp As Microsoft.Office.Interop.Outlook.Application = Nothing
 
 
        'SetApplicationFields(wordApp.Application)
 
        'If Not wordApp Is Nothing Then
        '    ToolBar = AddWordToolbar(wordApp, "Some useful toolbar.")
        'End If
 
 
 
 
        Dim insertText As Microsoft.Office.Core.CommandBarButton
        Dim styleText As Microsoft.Office.Core.CommandBarButton
 
        ' Visual Basic
        ' Create a toolbar.
        Dim toolbar As Microsoft.Office.Core.CommandBar = Nothing
        If Not wordApp Is Nothing Then
            toolbar = AddWordToolbar(wordApp, "Some useful toolbar.")
        End If
 
        ' Create a button to add text.
        insertText = MakeANewButton(toolbar, "Insert text", 1044, _
            AddressOf insertText_Click)
 
        ' Create a button to style selected text.
        styleText = MakeANewButton(toolbar, "Style text", 1081, _
            AddressOf styleText_Click)
 
End Sub
Danke im Voraus. ;)
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
CommandBar und CommandBarButton2.673AnyVBUser10.03.11 16:03
Re: CommandBar und CommandBarButton1.344Micke10.03.11 17:16
Re: CommandBar und CommandBarButton1.256AnyVBUser24.03.11 14:33

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel