Calling word Macros from .Net

While using Word automation with .Net sometimes it is required ti call, word macro’s from C# or VB.Net.

Here is the code to call word macros from VB.Net.

Dim WordApp As New Microsoft.Office.Interop.Word.Application
CType(WordApp, Object).GetType().InvokeMember("Run", Reflection.BindingFlags.Default Or Reflection.BindingFlags.InvokeMethod, Nothing, CType(WordApp, Object), New Object() {"helloworld"})

In the code, helloworld is the macro name.Or you can simply call WordApp.Run("helloworld") will also works fine.

 

You can also refer link from Microsoft
http://support.microsoft.com/kb/306683

Related content:

  1. Printing Infopath forms
This entry was posted in .Net, Miscellaneous, Office Interoperability and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>