Andrew Fergus
MrExcel MVP
- Joined
- Sep 9, 2004
- Messages
- 5,462
- Office Version
- 365
- 2021
- 2016
- Platform
- Windows
Hello
I'm a little bit out of my depth here and I'm looking for some help with Word VBA. I have a paragraph mark for which I need to change the style from "Heading 3" to "Normal".
The text flows as follows:
Normal text in normal style (CR)
(PM)
New Heading in Heading 3 style (CR)
where:
(CR) = carriage return or some such thing (i.e. the little arrow that drops down and left; it can be input using Alt 011)
(PM) = paragraph mark where the style is "Heading 3" (it looks like a backwards 'P' when you unhide the hidden characters)
Through VBA I can find the paragraph mark that has the style "Heading 3" but I need to change this to a "Normal" style, without changing the style of the line below.
To date all of my coding attempts have failed, these include selecting just the (PM) line and trying to set the style using a command like this:
Selection.Style = ActiveDocument.Styles("Normal")
I have also tried selecting the entire (PM) line as well as the entire line above and setting the style using the same command, to no avail. I have also tried setting the style to an intermediate style like "Heading 2" and then re-setting to "Normal" - again the style change doesn't work. I have also tried to brute force it with a command like this:
Selection.Style = "Normal"
again, it doesn't work.
Whilst I can re-set the style manually in the Word document, I can't get a macro to do this - given the document has hundreds of pages and I don't know how many stray paragraph marks there are, I think a macro is my only option - unless someone has another method? Any help with setting the style of the paragraph mark to "Normal" using VBA would be appreciated. I have spent way too long on this and it feels like it should be very easy!
Thanks in advance
Andrew
I'm a little bit out of my depth here and I'm looking for some help with Word VBA. I have a paragraph mark for which I need to change the style from "Heading 3" to "Normal".
The text flows as follows:
Normal text in normal style (CR)
(PM)
New Heading in Heading 3 style (CR)
where:
(CR) = carriage return or some such thing (i.e. the little arrow that drops down and left; it can be input using Alt 011)
(PM) = paragraph mark where the style is "Heading 3" (it looks like a backwards 'P' when you unhide the hidden characters)
Through VBA I can find the paragraph mark that has the style "Heading 3" but I need to change this to a "Normal" style, without changing the style of the line below.
To date all of my coding attempts have failed, these include selecting just the (PM) line and trying to set the style using a command like this:
Selection.Style = ActiveDocument.Styles("Normal")
I have also tried selecting the entire (PM) line as well as the entire line above and setting the style using the same command, to no avail. I have also tried setting the style to an intermediate style like "Heading 2" and then re-setting to "Normal" - again the style change doesn't work. I have also tried to brute force it with a command like this:
Selection.Style = "Normal"
again, it doesn't work.
Whilst I can re-set the style manually in the Word document, I can't get a macro to do this - given the document has hundreds of pages and I don't know how many stray paragraph marks there are, I think a macro is my only option - unless someone has another method? Any help with setting the style of the paragraph mark to "Normal" using VBA would be appreciated. I have spent way too long on this and it feels like it should be very easy!
Thanks in advance
Andrew