|
-
Nov 15th, 2005, 10:46 AM
#1
Thread Starter
Hyperactive Member
Looping through Word document for styles
Hi,
I want to loop through all the lines of a word document and get the style of that sentence, like Heading 1, Heading 2, normal etc.
How can I do this?
I know how to open a word document, but I don't know how to loop through all the sentences and grab the style.
Thanks.
vbcode1980
I code C#....

-
Nov 15th, 2005, 11:35 AM
#2
Re: Looping through Word document for styles
VB Code:
Dim p As Paragraph
For Each p In ActiveDocument.Paragraphs
Debug.Print p.Style, p.Range.Font.Name, p.Range.Font.Size
Next
This world is not my home. I'm just passing through.
-
Nov 16th, 2005, 03:25 AM
#3
Thread Starter
Hyperactive Member
Re: Looping through Word document for styles
Is there a way to find out the name of the heading like "Heading 1" or "Heading 3"?
I code C#....

-
Nov 16th, 2005, 04:16 AM
#4
Re: Looping through Word document for styles
Is there a way to find out the name of the heading like "Heading 1" or "Heading 3"?
That is exactly what p.Style gives you. I just threw in the font name and size in case you were interested.
I ran the code I gave you against a document with Heading1 and Heading2 styles and it listed them as expected. What results are you getting?
This world is not my home. I'm just passing through.
-
Nov 16th, 2005, 04:19 AM
#5
Thread Starter
Hyperactive Member
Re: Looping through Word document for styles
Hmm, I didn't get the heading names. Maybe there's something wrong with my test documents.
I'll try again.
Thanks
I code C#....

-
Nov 16th, 2005, 04:23 AM
#6
Re: Looping through Word document for styles
The code I gave you was a macro running in Word. It should be exactly the same in VB6 working on the ActiveDocument object.
What result do you get if you run the macro in word? If it works ok then I'd guess that your Word object isn't pointing at the document you think it is.
This world is not my home. I'm just passing through.
-
Nov 16th, 2005, 04:30 AM
#7
Thread Starter
Hyperactive Member
Re: Looping through Word document for styles
Strange..
Anyway, my boss wants it in .NET now, so I'm moving to the .NET forum.s
Because if I use this code in .NET I get 'System._ComObject' for style...
I code C#....

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|