none
Word Template Dev RRS feed

  • Question

  • I'm brand new to VS, literally just downloaded 2012 last night so please bear with my possible complete cluelessness. Concentrating on a custom Word dotm file here.

    We've created a Word 2010 dotm file by opening the Word 2003 template file (containing customizations and many, many VBA macros) that we and our client have been using for years. I've started customizing the ribbon using the CustomUI editor (http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2010/08/10/23248.aspx) as liked to from a Microsoft page but the editor is clunky at best and I saw that VS 2012 could have intellisense while coding XML. So, I loaded VS 2012 and am writing the XML in there (its GREAT!) and copying and pasting the code back to the Custom UI editor. Going a step further in VS I've set up a Word template project based on the dotm I've been customizing but from there I'm lost and before I spend too much time trying to figure what the best route I thought someone could answer these general questions.

    I don't see that I can get to or modify the VBA code that is currently in the template. Nor do I see where I can modify the XML that's customizing the ribbon. Am I correct in thinking that you can't do either of these things from VS when starting from an exiting template?

    It appears that you either write the customization/automation in VBA or in VS/.net, but you can't modify the VBA code in VS (which seems reasonable). Right?

    What are the Visual Studio Tools for Office? Are they built into 2012 or do I need to download something additional?

    Many thanks for reading this way-too-long post!
    Ken

    Sunday, April 21, 2013 12:37 PM

Answers

  • Hi Ken

    VBA plus an "embedded" Ribbon XML is only way to distribute a template (or document) as a single file.

    With a VSTO customization that includes a Ribbon you'll have multiple files: a manifest, the Ribbon xml file, the DLL with the "code behind"...

    All of these are generated when you build the solution. And then you require a Set-up for installation. This can be a standard *.msi or you can use the ClickOnce technology. These deploy the files to the correct folder structure on the client machine and register anything requiring COM registration under Windows.

    Editing the VBA after a template has been published shouldn't cause any problems - it won't "break" the solution. The only danger would be the same as you always have with Word: every once and a while the basic document structure can become damaged ("corrupted"). But if that would happen it wouldn't have anything to do with VSTO, directly.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by KenKrugh Monday, April 22, 2013 3:56 PM
    Monday, April 22, 2013 3:35 PM
    Moderator

All replies

  • Hi KenK,

    The VSTO can help you extend application in Microsoft Office, you can know more about VSTO from the below link:

    Visual Studio Tools for Office

    About Word Templates development, you can refer to the below article,From these articles, you can know how to create Word templates.

    Creating Word 2007 Templates Programmatically

    Word Template Project TemplateWorking with templatesFor how to extend VBA code in VSTO, you can refer to the below article to get more:

    Extend Your VBA Code With VSTO

    Chapter 12: Migrating VBA Solutions to VSTO

    VBA Interoperability with Visual Studio Tools for the Office System 

    From VBA Macro to Word Add-in

    I help those can help you, Thanks.


    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample

    Monday, April 22, 2013 3:26 AM
  • Hi Ken

    <<I don't see that I can get to or modify the VBA code that is currently in the template. Nor do I see where I can modify the XML that's customizing the ribbon. Am I correct in thinking that you can't do either of these things from VS when starting from an exiting template?

    It appears that you either write the customization/automation in VBA or in VS/.net, but you can't modify the VBA code in VS (which seems reasonable). Right?>>

    That is correct. If you're looking at the template in the Visual Studio "Designer", then you're using Visual Studio Tools for Office. A VSTO template can contain VBA, but you can't edit it from within Visual Studio. You'd have to close the project, open the template in Word and edit the VBA there.

    Note that if you start with a template containing macros then it will be a *.dotm template which could cause security issues (same as any *.dotm if a user's machine isn't set up to allow macros).

    As to the Ribbon: VSTO doesn't store the Ribbon XML in the Office document. It loads the Ribbon XML when the document loads from a separate file that's part of the VSTO project. And all the code in this Ribbon would have to link to code in the VSTO project, it can't link to your VBA code. (But the .NET code can call the VBA macros using Application.Run.)

    <<What are the Visual Studio Tools for Office? Are they built into 2012 or do I need to download something additional?>>

    If you're already viewing a template in Visual Studio, then you must already have VSTO installed. Do you see an "Office" category after choosing File/New? And you chose "Word template", then selected your template?

    If you don't have VSTO, then you'd need Visual Studio Professional (or "higher"). VSTO can't be bought separately.

    Whether you should migrate this template to VSTO depends a lot on what it is you'd want to accomplish by doing so...


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, April 22, 2013 8:07 AM
    Moderator
  • I don't have a lot of time right now to check out all those links but I'll definitely do so. Thanks for bringing it all together. From the quick look at things I've done it appears we're going to be better off staying with VBA, at least for this project.

    A couple last general questions though: When using a VSTO Word template project what is generated and deployed with the final build? Is it just a .dotm file? Does the .dotm file get "compiled" (so to speak?) to include the custom UI XML and are there any problems caused by editing that template with the VBA editor after it "comes out" of VSTO?

    Thanks again for replying with such great info and saving me a bunch of time reading through web page after web page.

    Best,
    Ken

    Monday, April 22, 2013 12:28 PM
  • Hi Ken

    VBA plus an "embedded" Ribbon XML is only way to distribute a template (or document) as a single file.

    With a VSTO customization that includes a Ribbon you'll have multiple files: a manifest, the Ribbon xml file, the DLL with the "code behind"...

    All of these are generated when you build the solution. And then you require a Set-up for installation. This can be a standard *.msi or you can use the ClickOnce technology. These deploy the files to the correct folder structure on the client machine and register anything requiring COM registration under Windows.

    Editing the VBA after a template has been published shouldn't cause any problems - it won't "break" the solution. The only danger would be the same as you always have with Word: every once and a while the basic document structure can become damaged ("corrupted"). But if that would happen it wouldn't have anything to do with VSTO, directly.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by KenKrugh Monday, April 22, 2013 3:56 PM
    Monday, April 22, 2013 3:35 PM
    Moderator
  • Thanks so much again Cindy. Again, saved me a bunch of time!!

    For anyone who might find this helpful, this is what I've done to be able to use the far superior VS XML editor to modify the UI XML:

    I created a project in Visual Studio, and added an XML file. When that XML file opened in the XML editor I simply open the dotm file in the "Custom UI" editor from the Open XML folks, did a Ctrl + A , copied that entire thing and overwrote the XML code that was in the VS XML file. VS "saw" the first line of XML and knew which schema it needed to associate the XML file with and (whoot!) I had intellisense.

    After making changes that I wanted to test I simply did a CTRL + A in VS, copied everything and pasted it back to the Custom UI editor, where I save and close the template. The VS project is nothing I'll save, its only there to use the XML editor.

    Not exactly straight forward, I know, but given that I've not been unable to get even undo to work in the Custom UI editor and now have search and replace and intellisense, its been worth it for me.

    Thanks again to all!

    Monday, April 22, 2013 3:55 PM