michelle
06-19-2005, 08:06 AM
Dear VBA Word users,
We are busy to get a button on Word 2000, the button must call a function and not a macro, the code we made starts the function directly and pressing the button nothing is happening.
Can someone pls look ad the code of AddButton and give a suggestion what goes wrong. Code starts with function: runSome
Nice regards,
Michelle. :dunno
Code:
_______________________________________________________
Option Explicit
Private strButton
Function runSome()
strButton = "test"
RemoveAddButton
AddButton
End Function
Private Sub RemoveAddButton()
On Error GoTo ErrHandler
Dim N As Integer
Dim oBar As Office.CommandBar
Dim oButton As Office.CommandBarButton
Documents.Add DocumentType:=wdNewBlankDocument
Set oBar = Application.ActiveDocument.CommandBars("Standard")
For N = oBar.Controls.Count To 1 Step -1
If oBar.Controls.Item(N).Caption = strButton Then
oBar.Controls.Item(N).Delete
End If
Next N
Set oButton = Nothing
Set oBar = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description
Set oButton = Nothing
Set oBar = Nothing
End Sub
Private Sub AddButton()
On Error GoTo ErrHandler
Dim oBar As Office.CommandBar
Dim oButton As Office.CommandBarButton
Set oBar = Application.ActiveDocument.CommandBars("Standard")
Set oButton = oBar.Controls.Add(Type:=msoControlButton, Before:=1, Temporary:=True)
With oButton
.Caption = strButton
.FaceId = 1000
.Style = msoButtonIconAndCaption
.Application = printTest()
' .OnAction = printTest()
' .OnAction = printTest()
End With
Set oButton = Nothing
Set oBar = Nothing
Exit Sub
ErrHandler:
MsgBox "AddButton " & Err.Description
Set oButton = Nothing
Set oBar = Nothing
End Sub
Private Function printTest()
MsgBox "test"
End Function
_______________________________________________________
We are busy to get a button on Word 2000, the button must call a function and not a macro, the code we made starts the function directly and pressing the button nothing is happening.
Can someone pls look ad the code of AddButton and give a suggestion what goes wrong. Code starts with function: runSome
Nice regards,
Michelle. :dunno
Code:
_______________________________________________________
Option Explicit
Private strButton
Function runSome()
strButton = "test"
RemoveAddButton
AddButton
End Function
Private Sub RemoveAddButton()
On Error GoTo ErrHandler
Dim N As Integer
Dim oBar As Office.CommandBar
Dim oButton As Office.CommandBarButton
Documents.Add DocumentType:=wdNewBlankDocument
Set oBar = Application.ActiveDocument.CommandBars("Standard")
For N = oBar.Controls.Count To 1 Step -1
If oBar.Controls.Item(N).Caption = strButton Then
oBar.Controls.Item(N).Delete
End If
Next N
Set oButton = Nothing
Set oBar = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description
Set oButton = Nothing
Set oBar = Nothing
End Sub
Private Sub AddButton()
On Error GoTo ErrHandler
Dim oBar As Office.CommandBar
Dim oButton As Office.CommandBarButton
Set oBar = Application.ActiveDocument.CommandBars("Standard")
Set oButton = oBar.Controls.Add(Type:=msoControlButton, Before:=1, Temporary:=True)
With oButton
.Caption = strButton
.FaceId = 1000
.Style = msoButtonIconAndCaption
.Application = printTest()
' .OnAction = printTest()
' .OnAction = printTest()
End With
Set oButton = Nothing
Set oBar = Nothing
Exit Sub
ErrHandler:
MsgBox "AddButton " & Err.Description
Set oButton = Nothing
Set oBar = Nothing
End Sub
Private Function printTest()
MsgBox "test"
End Function
_______________________________________________________