Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Wed, 14 Dec 2005 16:45:02 -0500,    group: microsoft.public.word.oleinterop        back       


Can I call OfficeCodeBehind (vsto) methods from a Windows Forms app?   
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.
date: Wed, 14 Dec 2005 16:45:02 -0500   author:   DarrylR

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us