none
show the word 2008 heading styles collection in vb.net RRS feed

  • Question

  • I am developing a program which uses the MS Word (Office 2007) as a report generator.

    In the user-SetUp form I want the user to select which heading styles he/she want to use. I want to show a ComboList with all avaliable heading styles from where the user can select the appropriate heading styles.

    But I am just about giving up, I can not find any leads of how to do this - anybody cares to give me a hand ??

    Am using the Visual Studio 2008 (vb.net)


    levesen
    Thursday, July 21, 2011 8:32 PM

Answers

  • Thanks a lot Cindy, that solved the problem, the structure:

    m_wdApp = CreateObject("word.application")
    m_wdApp.Application.Visible = False
    Dim Doc As Wd.Document = m_wdApp.Documents.Add()
    cboFrontPageStyle1.Items.Add(Doc.Styles(Microsoft.Office.Interop.Word.WdBuiltinStyle.wdStyleHeading1).NameLocal)
    ..
    ..

    Doc = Nothing
    m_wdApp.Quit()
    m_wdApp = Nothing

    is working beautifully

    thanks again to both of you.
    Jorgen


    levesen
    • Marked as answer by levesen Friday, July 22, 2011 2:37 PM
    Friday, July 22, 2011 2:37 PM

All replies

  • Hi levesen

    I'm not 100% sure about the question, but perhaps the following observation will help:

    Word has nine levels of built-in heading style, and only the nine. They're names are "Heading " & LevelNumer (so "Heading 1", Heading 2", etc.)

    I would think you could just fill the list with those string values, statically?


    Cindy Meister, VSTO/Word MVP
    Friday, July 22, 2011 7:17 AM
    Moderator
  • Hello,

    Is Document.Styles what you are looking for?


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Friday, July 22, 2011 7:33 AM
  • Hei Cindy,

    Yes that is what I have done so far, but as this program of mine is multilanguage I have to supply these names in the users language. In my language "heading 1" is equal to "Overskrift 1" - that is why I have to read those names beforehand.

    Kind regards
    Jorgen

     


    levesen

    Friday, July 22, 2011 8:32 AM
  • Could be, can you please give me a short example of use (vb.net) ?

    Kind regards
    Jorgen


    levesen
    Friday, July 22, 2011 8:47 AM
  • Hi Jorgen

    Ah, I wondered if it was something like that :-)

    Yes, you can do that. The Style object has a NameLocal property you can read. So something like this:

      Debug.Print "Heading Style 1 local name: " & theDoc.Styles(Word.WdBuiltinStyle.wdStyleHeading1).NameLocal


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by levesen Friday, July 22, 2011 2:09 PM
    • Unmarked as answer by levesen Friday, July 22, 2011 2:10 PM
    Friday, July 22, 2011 8:53 AM
    Moderator
  • Thanks a lot Cindy, that solved the problem, the structure:

    m_wdApp = CreateObject("word.application")
    m_wdApp.Application.Visible = False
    Dim Doc As Wd.Document = m_wdApp.Documents.Add()
    cboFrontPageStyle1.Items.Add(Doc.Styles(Microsoft.Office.Interop.Word.WdBuiltinStyle.wdStyleHeading1).NameLocal)
    ..
    ..

    Doc = Nothing
    m_wdApp.Quit()
    m_wdApp = Nothing

    is working beautifully

    thanks again to both of you.
    Jorgen


    levesen
    • Marked as answer by levesen Friday, July 22, 2011 2:37 PM
    Friday, July 22, 2011 2:37 PM