lucysean
January 11th, 2000, 08:44 PM
Hi,
Thank you for your patience to read my mail.
What I did in WORD2000 is that firstly I created a template named
"Normal1.dot". I can add some modeles and classes to the project of the dot
file in the Macro VB Editor.I defined three variable as
Office.CommandBarButton though using "WithEvents".The buttons were created
by a modele named "modSharedCode", which its functions can return variable
as Office.CommandBarButton. So I'm able to fire the button's click event and
then continue the program.
The document events including "new","open" and "close" are as follows:
option Explicit
' public module-level variables.
public withevents p_ctlBtnEvents as Office.CommandBarButton
public withevents x_ctlBtnEvents as Office.CommandBarButton
public withevents y_ctlBtnEvents as Office.CommandBarButton
private Sub Document_Close()
Dim ftptest as new ftpclass 'create a new ftpclass
Select Case Select_Button
Case "save"
......
Case "local"
......
Case "exit
......
Word.Application.Quit false
Case else
......
End Select
End Sub
private Sub Document_New()
Select_Button = " "
set p_ctlBtnEvents = CreateAddInSaveButton() 'create Save Button
set x_ctlBtnEvents = CreateAddInLocalButton() 'create Local Button
set y_ctlBtnEvents = CreateAddInExitButton() 'create Exit Button
End Sub
private Sub Document_Open()
Select_Button = " "
set p_ctlBtnEvents = CreateAddInSaveButton() 'create Save Button
set x_ctlBtnEvents = CreateAddInLocalButton() 'create Local Button
set y_ctlBtnEvents = CreateAddInExitButton() 'create Exit Button
End Sub
'------------------------------------------------------
' This event occurs when the user clicks the menu
' command for the add-in in the Office application.
'------------------------------------------------------
public Sub p_ctlBtnEvents_Click(byval Ctrl as Office.CommandBarButton, _
CancelDefault as Boolean)
on error GoTo Event_Err
......
Event_End:
Exit Sub
Event_Err:
AddInErr Err
resume Event_End
End Sub
'save the file to local machine
public Sub x_ctlBtnEvents_Click(byval Ctrl as Office.CommandBarButton, _
CancelDefault as Boolean) 'click "保*至本地"
on error GoTo Event_Err
......
Event_End:
Exit Sub
Event_Err:
AddInErr Err
resume Event_End
End Sub
public Sub y_ctlBtnEvents_Click(byval Ctrl as Office.CommandBarButton, _
CancelDefault as Boolean) 'click "不保*退出"
on error GoTo Event_Err
......
Event_End:
Exit Sub
Event_Err:
AddInErr Err
resume Event_End
End Sub
But in WORD97 it told me that p_ctlBtnEvents can't be defined though
"WithEvents" keyword. Once I deleted the "WithEvents" of the definition,the
code was able to be compiled. But the click events of three buttons in my
custom commandbar for WORD can't be fired. I tried to use the "OnAction"
property of the button, but anyway it can't help me to grasp the click
events. So the result is that I add a custom commandbar but no button can
work when it's clicked.
Thank you again. Please help me find the problem of my code.
^.^
Lucy.H.Zhang
Thank you for your patience to read my mail.
What I did in WORD2000 is that firstly I created a template named
"Normal1.dot". I can add some modeles and classes to the project of the dot
file in the Macro VB Editor.I defined three variable as
Office.CommandBarButton though using "WithEvents".The buttons were created
by a modele named "modSharedCode", which its functions can return variable
as Office.CommandBarButton. So I'm able to fire the button's click event and
then continue the program.
The document events including "new","open" and "close" are as follows:
option Explicit
' public module-level variables.
public withevents p_ctlBtnEvents as Office.CommandBarButton
public withevents x_ctlBtnEvents as Office.CommandBarButton
public withevents y_ctlBtnEvents as Office.CommandBarButton
private Sub Document_Close()
Dim ftptest as new ftpclass 'create a new ftpclass
Select Case Select_Button
Case "save"
......
Case "local"
......
Case "exit
......
Word.Application.Quit false
Case else
......
End Select
End Sub
private Sub Document_New()
Select_Button = " "
set p_ctlBtnEvents = CreateAddInSaveButton() 'create Save Button
set x_ctlBtnEvents = CreateAddInLocalButton() 'create Local Button
set y_ctlBtnEvents = CreateAddInExitButton() 'create Exit Button
End Sub
private Sub Document_Open()
Select_Button = " "
set p_ctlBtnEvents = CreateAddInSaveButton() 'create Save Button
set x_ctlBtnEvents = CreateAddInLocalButton() 'create Local Button
set y_ctlBtnEvents = CreateAddInExitButton() 'create Exit Button
End Sub
'------------------------------------------------------
' This event occurs when the user clicks the menu
' command for the add-in in the Office application.
'------------------------------------------------------
public Sub p_ctlBtnEvents_Click(byval Ctrl as Office.CommandBarButton, _
CancelDefault as Boolean)
on error GoTo Event_Err
......
Event_End:
Exit Sub
Event_Err:
AddInErr Err
resume Event_End
End Sub
'save the file to local machine
public Sub x_ctlBtnEvents_Click(byval Ctrl as Office.CommandBarButton, _
CancelDefault as Boolean) 'click "保*至本地"
on error GoTo Event_Err
......
Event_End:
Exit Sub
Event_Err:
AddInErr Err
resume Event_End
End Sub
public Sub y_ctlBtnEvents_Click(byval Ctrl as Office.CommandBarButton, _
CancelDefault as Boolean) 'click "不保*退出"
on error GoTo Event_Err
......
Event_End:
Exit Sub
Event_Err:
AddInErr Err
resume Event_End
End Sub
But in WORD97 it told me that p_ctlBtnEvents can't be defined though
"WithEvents" keyword. Once I deleted the "WithEvents" of the definition,the
code was able to be compiled. But the click events of three buttons in my
custom commandbar for WORD can't be fired. I tried to use the "OnAction"
property of the button, but anyway it can't help me to grasp the click
events. So the result is that I add a custom commandbar but no button can
work when it's clicked.
Thank you again. Please help me find the problem of my code.
^.^
Lucy.H.Zhang