none
How to convert MS Word 2007 Addin(C#) to Word Macro(VBA)? RRS feed

  • Question

  • Hi Guys,

    I created an MS Word 2007 Addin and i want to convert it to a Macro, is there any facility to convert it to a macro?

    Can i install the Addin to a selected Word Doc and not to all the word docs? If it can be done, please tell me the way to get that done?

    Thanks in advance.

    Regards,
    Srinivas
    Thursday, April 14, 2011 11:23 AM

Answers

  • Hi Srinivas

     

    You’ll probably first have to convert your code to VB.net and then make the final changes by hand to get it pure VBA.

     

    Doing a search I found some free converters.  You could try one of these and see how it does.

     

    http://www.carlosag.net/Tools/CodeTranslator/

    http://converter.telerik.com/

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

     

    Hope these help.

     


    Regards
    • Marked as answer by Srinivas39 Thursday, April 14, 2011 3:25 PM
    Thursday, April 14, 2011 12:36 PM
  • Hi Srinivas

    <<Can i install the Addin to a selected Word Doc and not to all the word docs?>>

    VBA is always stored in a document (or template file), either docm or dotm file extension. Where it's stored deterimines its scope. This can get quite complex and the information would actually not belong in the VSTO forum, but...

    1. For VBA to have application-level scope it must be stored in a template (dotm) and that template must be loaded as an add-in. In order to have Word load it automatically, the template must be saved in the user's STARTUP folder. A template add-in can also be loaded on-demand, in this case, you use the bottom half of the Document Template dialog (Developer tab of the Ribbon).

    2. Other than that, macros are always document-specific. Macros stored in a template, from which new documents are created, are available to all such documents. You can see whether a document is linked to such a template - and you can link any document to such a template - in the top part of that same Document Template dialog.

    3. Macro code stored directly in a document (docm) file is available only to that document.

    Similar rules also apply to the user interface (Ribbon). In this case, you must use Ribbon XML and that file must be integrated into the docm "XML Package". A useful tool for this is the Custom UI Editor, available at OpenXMLDeveloper.org.

    A VBA solution cannot use a Custom Task Pane.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Srinivas39 Thursday, April 14, 2011 3:25 PM
    Thursday, April 14, 2011 12:44 PM
    Moderator
  • Here I developed a Addin which will add a ribbon tab, some key stroke events and custom task pane on key events to the Word. I got succeded in developping a Addin But i need to deploy the same on a web server. So that Client should be able to access the word with the addin installed. Will a template on which Addin installed, can be useful here?

    As you said, if VBA doesn't allow Custom Task Pane, i'll be in trouble again.



    Hi Srinivas

    Yes, that's why I specifically mentioned that VBA can't use custom task panes. Useful, aren't they :-)?

    I'm not sure I completely understand what it is you want to do, but...

    A VSTO or COM Add-in cannot be associated with or installed to a template. An Add-in must be installed IN the user's machine and registered in Windows. They're not designed to work in an "embedded state" (in a Word window within another application)  and Word is not designed to run server-side.

    If you're trying to provide editing capability on a web-site I think you need to use something other than Word...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Srinivas39 Thursday, April 14, 2011 3:25 PM
    Thursday, April 14, 2011 2:16 PM
    Moderator

All replies

  • Hi Srinivas

     

    You’ll probably first have to convert your code to VB.net and then make the final changes by hand to get it pure VBA.

     

    Doing a search I found some free converters.  You could try one of these and see how it does.

     

    http://www.carlosag.net/Tools/CodeTranslator/

    http://converter.telerik.com/

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

     

    Hope these help.

     


    Regards
    • Marked as answer by Srinivas39 Thursday, April 14, 2011 3:25 PM
    Thursday, April 14, 2011 12:36 PM
  • Hi Srinivas

    <<Can i install the Addin to a selected Word Doc and not to all the word docs?>>

    VBA is always stored in a document (or template file), either docm or dotm file extension. Where it's stored deterimines its scope. This can get quite complex and the information would actually not belong in the VSTO forum, but...

    1. For VBA to have application-level scope it must be stored in a template (dotm) and that template must be loaded as an add-in. In order to have Word load it automatically, the template must be saved in the user's STARTUP folder. A template add-in can also be loaded on-demand, in this case, you use the bottom half of the Document Template dialog (Developer tab of the Ribbon).

    2. Other than that, macros are always document-specific. Macros stored in a template, from which new documents are created, are available to all such documents. You can see whether a document is linked to such a template - and you can link any document to such a template - in the top part of that same Document Template dialog.

    3. Macro code stored directly in a document (docm) file is available only to that document.

    Similar rules also apply to the user interface (Ribbon). In this case, you must use Ribbon XML and that file must be integrated into the docm "XML Package". A useful tool for this is the Custom UI Editor, available at OpenXMLDeveloper.org.

    A VBA solution cannot use a Custom Task Pane.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Srinivas39 Thursday, April 14, 2011 3:25 PM
    Thursday, April 14, 2011 12:44 PM
    Moderator
  • Hi Cindy,

    Thank you for your Reply,                                               

    Here I developed a Addin which will add a ribbon tab, some key stroke events and custom task pane on key events to the Word. I got succeded in developping a Addin But i need to deploy the same on a web server. So that Client should be able to access the word with the addin installed. Will a template on which Addin installed, can be useful here?

    As you said, if VBA doesn't allow Custom Task Pane, i'll be in trouble again.

    Can you please give a solution to my problem?

    Regards,                                                                                                                        Srinivas




    Thursday, April 14, 2011 1:27 PM
  • Here I developed a Addin which will add a ribbon tab, some key stroke events and custom task pane on key events to the Word. I got succeded in developping a Addin But i need to deploy the same on a web server. So that Client should be able to access the word with the addin installed. Will a template on which Addin installed, can be useful here?

    As you said, if VBA doesn't allow Custom Task Pane, i'll be in trouble again.



    Hi Srinivas

    Yes, that's why I specifically mentioned that VBA can't use custom task panes. Useful, aren't they :-)?

    I'm not sure I completely understand what it is you want to do, but...

    A VSTO or COM Add-in cannot be associated with or installed to a template. An Add-in must be installed IN the user's machine and registered in Windows. They're not designed to work in an "embedded state" (in a Word window within another application)  and Word is not designed to run server-side.

    If you're trying to provide editing capability on a web-site I think you need to use something other than Word...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Srinivas39 Thursday, April 14, 2011 3:25 PM
    Thursday, April 14, 2011 2:16 PM
    Moderator
  • Yes, that's why I specifically mentioned that VBA can't use custom task panes. Useful, aren't they :-)?

    A VSTO or COM Add-in cannot be associated with or installed to a template. An Add-in must be installed IN the user's machine and registered in Windows. They're not designed to work in an "embedded state" (in a Word window within another application)  and Word is not designed to run server-side.

    If you're trying to provide editing capability on a web-site I think you need to use something other than Word...
    You are right Cindy, Thank you very much.
    Thursday, April 14, 2011 3:25 PM