none
How to export a style from Word to an external file using vb.net RRS feed

  • Question

  • I've designed a new multilevel list style in my copy of Word. I want to be able to export that to an external file, then later import it into someone else's copy of Word. Can this be done? How?

    Robert Homes

    Tuesday, June 23, 2015 1:57 PM

Answers

  • Hi Robert

    Mmmm... Closest you can get to what you envision would be the WordOpenXML for the style, but I'm not sure whether that helps you in this scenario.

    Otherwise, you'd need to "read" all the style properties and write them to a file, somewhere, then read that and create the style from scratch.

    Going back to the Open XML scenario: Would the user need to have this template open in Word, or could he give you access to it as a file? If you can get access to the file then the Open XML SDK method would be possible. In a nutshell, you could have the "parts" of the xml as xml and insert them into the file's existing xml. Affected would be (at minimum) the styles.xml and the numbering.xml.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Robert Homes Wednesday, June 24, 2015 3:22 PM
    Tuesday, June 23, 2015 4:30 PM
    Moderator
  • Hi Robert,

    About Open XML, you may refer to this article:

    # Extract styles from a word processing document (Open XML SDK)

    https://msdn.microsoft.com/en-us/library/office/hh181052.aspx?f=255&MSPPError=-2147217396

    For the additional issues, they are not directly related to the original issue, it would be better if you open up a new thread for the new question. In this way, our discussion here will not deviate too much from the original issue. This will make answer searching in the forum easier and be beneficial to other community members as well.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Robert Homes Wednesday, June 24, 2015 3:24 PM
    Wednesday, June 24, 2015 2:49 AM
    Moderator

All replies

  • Hi Robert

    Word has a tool that's no longer as discoverable as it once was: the Organizer. With it, styles and macros can be copied from one document to another. You can see it in the UI if you

    1. display the Styles task pane
    2. click on "Manage styles" (right-most button, at the bottom)
    3. Choose a style
    4. Click Import/Export

    In the object model it's Word.Application.OrganizerCopy


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, June 23, 2015 3:05 PM
    Moderator
  • Cindy: So that's where they put the Organizer! Glad to know that. But..., the ORganizer only seems capable of exporting a style from one Word document or template to another Word document or template. Is there a way to export a style to a CSV or normal text file or some other file external to word? (I want to do that because I need to be able to later IMPORT the style into a Word template on someone else's computer, and that someone else will usually be at some other internet location, not at my house or on my network. Also, I want to be able to do this in vb.net; how would you do that? Thanks.

    Robert Homes


    Tuesday, June 23, 2015 4:13 PM
  • Hi Robert

    Mmmm... Closest you can get to what you envision would be the WordOpenXML for the style, but I'm not sure whether that helps you in this scenario.

    Otherwise, you'd need to "read" all the style properties and write them to a file, somewhere, then read that and create the style from scratch.

    Going back to the Open XML scenario: Would the user need to have this template open in Word, or could he give you access to it as a file? If you can get access to the file then the Open XML SDK method would be possible. In a nutshell, you could have the "parts" of the xml as xml and insert them into the file's existing xml. Affected would be (at minimum) the styles.xml and the numbering.xml.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Robert Homes Wednesday, June 24, 2015 3:22 PM
    Tuesday, June 23, 2015 4:30 PM
    Moderator
  • Cindy:

    I don't know anything about Open XML or how to write "style properties" to a file. But I have looked into an alternative that I think could work, but I'll need help to get it working. (Another problem I'm having is that MultiList styles don't show up in the list of styles in Word. They appear to be a separate animal only viewed through the MultiList button on the Insert ribbon. Thus, I can't see them in the Organizer.)

    What I did was start Word's Macro Recorder, then I manually created and designed a new MultiList style. Then I stopped macro recording and went to the VBA editor in Word and found that the Macro Recorded did in fact save my work in a macro, which I called "FavList". Then I used File/Export in the VbA Editor to export that macro to a file, and that created a filed called "FavList.bas". So that got me the code I need to create the Style from scratch.

    Now I need to know how to do two more things:

    (1) how to import the macro in FavList.bas into the VBA editor. I can do that manually in the VBA editor, but when I try to use the Macro Recorder to record what I did manually, it didn't record anything (except me moving to the VBA Editor - it stopped there. So what I need to do is figure out how to write some vb.net code in my external program that will import the file.

    (2) Then I need to know how to save the macro (once imported) into Word's Normal template. When I try to do that manually, I get an error saying the Normal Template is read only. If I can't save it in Normal, then it will be lost once the user quits Word.

    Hope you're willing and able to help me with these things.


    Robert Homes


    Tuesday, June 23, 2015 7:12 PM
  • Hi Robert,

    About Open XML, you may refer to this article:

    # Extract styles from a word processing document (Open XML SDK)

    https://msdn.microsoft.com/en-us/library/office/hh181052.aspx?f=255&MSPPError=-2147217396

    For the additional issues, they are not directly related to the original issue, it would be better if you open up a new thread for the new question. In this way, our discussion here will not deviate too much from the original issue. This will make answer searching in the forum easier and be beneficial to other community members as well.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Robert Homes Wednesday, June 24, 2015 3:24 PM
    Wednesday, June 24, 2015 2:49 AM
    Moderator
  • Starain:

    Thanks for the info about Open XML, but I think that is getting too complicated for me. For now, I'm hoping I can find out how to import the .BAS file I created into Word's Normal template. I created/opened a new thread for that.


    Robert Homes

    Wednesday, June 24, 2015 3:49 AM
  • The simplest approach is to base both documents on the same template and add the Style to that.

    The next simplest approach is to replicate any paragraph break formatted in that Style in another document, either by copy/paste or using the .FormattedText method. You can then use the same process for replicating the Style in your other document at a later time.

    Or you can resort to using the Organizer, as Cindy suggests.

    Any of these approaches can be done programmatically.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, June 24, 2015 7:51 AM