D
DarrylR
Is it possible to call OfficeCodeBehind methods externally? I have created a
Word 2003 template using VSTO 2003, and I would like to call a few of the
methods implemented in the OfficeCodeBehind class from a Windows Forms
application. I know that I can link the methods to CommandBar buttons and
execute them by calling the CommandBarButton.Execute method. What I'm hoping
to do is call them using a syntax similar to the Application.Run syntax that
is used to execute VBA macros.
Here's how I'm calling a method implemented in the OfficeCodeBehind class
from my Windows Forms application now:
object objTemplatePath = "c:\\program files\\microsoft
office\\templates\\FirstVSTOtemplate.dot";
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.ApplicationClass objApp = new
Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document objDoc = objApp.Documents.Add(ref
objTemplatePath, ref oMissing, ref oMissing, ref oMissing);
Office.CommandBarControl cbc = objDoc.CommandBars["Menu
Bar"].Controls["Custom Code"];
Office.CommandBarButton cbb =
(Office.CommandBarButton)((Office.CommandBarPopup)cbc).Controls["Populate
Scalars"];
cbb.Execute();
I created a method called PopulateScalars() in OfficeCodeBehind that is
hooked to the Click event of the 'Populate Scalars' menu item. The code
above executes the method, but I have no way to determine when the method
has finished, or what the return value is. What I would like to do ideally
is call the PopulateScalars method directly from my Windows Forms
application.
Any help will be greatly appreciated.
Thanks,
Darryl R.
Word 2003 template using VSTO 2003, and I would like to call a few of the
methods implemented in the OfficeCodeBehind class from a Windows Forms
application. I know that I can link the methods to CommandBar buttons and
execute them by calling the CommandBarButton.Execute method. What I'm hoping
to do is call them using a syntax similar to the Application.Run syntax that
is used to execute VBA macros.
Here's how I'm calling a method implemented in the OfficeCodeBehind class
from my Windows Forms application now:
object objTemplatePath = "c:\\program files\\microsoft
office\\templates\\FirstVSTOtemplate.dot";
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.ApplicationClass objApp = new
Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document objDoc = objApp.Documents.Add(ref
objTemplatePath, ref oMissing, ref oMissing, ref oMissing);
Office.CommandBarControl cbc = objDoc.CommandBars["Menu
Bar"].Controls["Custom Code"];
Office.CommandBarButton cbb =
(Office.CommandBarButton)((Office.CommandBarPopup)cbc).Controls["Populate
Scalars"];
cbb.Execute();
I created a method called PopulateScalars() in OfficeCodeBehind that is
hooked to the Click event of the 'Populate Scalars' menu item. The code
above executes the method, but I have no way to determine when the method
has finished, or what the return value is. What I would like to do ideally
is call the PopulateScalars method directly from my Windows Forms
application.
Any help will be greatly appreciated.
Thanks,
Darryl R.