How to modify and updte specific styles for specific paragraphs across the document

Joined
Sep 17, 2020
Messages
1
Reaction score
0
I have word document with different styles like heading1, heading2, normal, bodytext etc. I'm trying to write a VBA macro which will first modify the styles as per requirement and then apply those styles across the document accordingly. See below, I'm changing the font size first for style=normal and heding1 and then want to apply it for all paragraphs where style=normal is already defined. So it will update the style for existing heading1 and normal separately.
NOTE: I want to do it with style only. I can do it using for loop by going each paragraph one by one and then find what is the style of that paragraph and then apply the style accordingly and it is working perfectly if I do in this way but in my document I have 60000 paragraphs and so it is taking long time like 10 hours. So, Im looking for a way to do it for each different styles in one shot. Please let me know if there is any way to do it.

There is easy option available in word doc. If I want to modify the NORMAL style then need to right click on NORMAL style and then modify it accordingly, Then Click on "Find all Normal instances" and then "Update Normal to match selection". But unfortunately I cant find any VBA code similar to this.

I tried many ways like below. But the problem is lets say in a paragraph you have two different font size. then it will not change both the font size at 12. Attaching a sample word doc. You can see that first paragraph has two different font size and using the below code it is changing only one font size to 12.

ActiveDocument.Styles(wdStyleNormal).Font.Name = "Arial"
ActiveDocument.Styles(wdStyleNormal).Font.Size = 12
ActiveDocument.UpdateStyles

OR

With ActiveDocument.Styles("wdStyleNormal").Font
.Name = "Arial"
.Size = 12
End With
With ActiveDocument.Styles("wdStyleNormal")
.AutomaticallyUpdate = True
End With
 

Attachments

  • sample_doc1.docx
    90.2 KB · Views: 132

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top