michelle
06-20-2005, 02:34 AM
Dear Word VBA users,
At the moment I am trying to get with the help of a self made and registered dll file a button on Word 2003, everything goes well only when the button is pressed a macro with the name "PrintTest" is being searched. Such a macro is not available so the function is not activate. Can someone tell me pls how I change the code to start by pressing the button the function "PrintTest".
I tried:
.OnAction = "PrintTest"
.OnAction = "PrintTest()"
.OnAction = "=PrintTest()"
Thanks for any help.
Michelle. :dunno
Source code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Option Explicit
Private strButton
Private Sub Class_Initialize()
strButton = "test"
RemoveAddButton
AddButton
End Sub
Private Sub RemoveAddButton()
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
End Sub
Private Sub AddButton()
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
.OnAction = "PrintTest"
End With
Set oButton = Nothing
Set oBar = Nothing
End Sub
Public Sub PrintTest()
MsgBox "this is a test of me"
End Sub
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
At the moment I am trying to get with the help of a self made and registered dll file a button on Word 2003, everything goes well only when the button is pressed a macro with the name "PrintTest" is being searched. Such a macro is not available so the function is not activate. Can someone tell me pls how I change the code to start by pressing the button the function "PrintTest".
I tried:
.OnAction = "PrintTest"
.OnAction = "PrintTest()"
.OnAction = "=PrintTest()"
Thanks for any help.
Michelle. :dunno
Source code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Option Explicit
Private strButton
Private Sub Class_Initialize()
strButton = "test"
RemoveAddButton
AddButton
End Sub
Private Sub RemoveAddButton()
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
End Sub
Private Sub AddButton()
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
.OnAction = "PrintTest"
End With
Set oButton = Nothing
Set oBar = Nothing
End Sub
Public Sub PrintTest()
MsgBox "this is a test of me"
End Sub
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%