Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Errors when looping through Word doc. Styles (.NET / Office XP)

    Hi,

    I am attempting to loop through the styles of a Word document and add each one to a ComboBox on Form2. However, when I run the code, the ComboBox is filled with the following text:

    "System.__ComObject"

    I am at a complete loss!

    Here is my code:

    Private Sub MDIForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim i As Integer
    Dim f As New Form2()
    Dim objWord As Word.Application

    objWord = GetObject(, "Word.Application")
    For i = 1 To objWord.ActiveDocument.Styles.Count
    f.ComboBox1.Items.Add (objWord.ActiveDocument.Styles.Item(i))
    f.Show()
    Next
    End Sub

    Any help on what the problem is would be much appreciated

    Thanks,

    Chris

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Errors when looping through Word doc. Styles (.NET / Office XP)

    Presumably it is the Name of the font that you want in the Combobox, this is available from the NameLocal Property of the Style.

    If you look at the attachments on Post 125342 on this board you will see an example of filling a Combobox with style names.

    Depending on what you are doing you may also want to do different things with Paragraph and Character Styles. You do this with <font color=blue>Style.Type = wdStyleTypeCharacter</font color=blue>

    StuartR

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Errors when looping through Word doc. Styles (.NET / Office XP)

    Have you gotten the code to work in VB 6?
    I would try that before using VB.Net.
    Then ley the VB.Net upgrade wizard try to convert the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •