Hello.
I'm trying to set up a document template for generating reports. I've been through and created the layout, created all the styles etc. etc., and have been trying to set up some VBA which will reset all the styles I have defined to preset values, in case someone fiddles with everything where they shouldn't.
I have created (admittedly using the Macro recorder to save myself typing) subroutines that contain the format settings for each of the styles in use (Section Heading, Paragraph Heading etc.), however annoyingly if the formatting of the document is changed, running the appropriate subroutine only resets the style if the particular amended text is highlighted.
For example (and for clarity):
If I change the tab settings on the style 'Section Headings' from a single tab at 2.5cm to a single tab at 6cm, and then run the appropriate settings macro, it only resets the tabs on the altered line if either the cursor is somewhere IN that line, or if that line is highlighted.
My question therefore is two-fold:
a) how do I convince Word/VBA to change these things back even if the cursor is NOT in the line of text? (I suspect this may be impossible as Word is creating 'hidden' intermediate styles, hence the style name for these styles won't match the pre-defined ones in the code (ie. the style name would be 'Section Heading + 14pt. Arial' instead of 'Section Heading')
b) Is there a way to select all instances of a particular style in VBA (ie. like using the 'Select all instances of this style' menu option from the Styles and Formatting toolbox) so that I can just cycle through each style name in code and select all instances of it before running the reset code?
I can provide a sample document with the code I have so far if needed.
Many thanks in advance for the torrent of help I'm potentially about to receive!
I'm trying to set up a document template for generating reports. I've been through and created the layout, created all the styles etc. etc., and have been trying to set up some VBA which will reset all the styles I have defined to preset values, in case someone fiddles with everything where they shouldn't.
I have created (admittedly using the Macro recorder to save myself typing) subroutines that contain the format settings for each of the styles in use (Section Heading, Paragraph Heading etc.), however annoyingly if the formatting of the document is changed, running the appropriate subroutine only resets the style if the particular amended text is highlighted.
For example (and for clarity):
If I change the tab settings on the style 'Section Headings' from a single tab at 2.5cm to a single tab at 6cm, and then run the appropriate settings macro, it only resets the tabs on the altered line if either the cursor is somewhere IN that line, or if that line is highlighted.
My question therefore is two-fold:
a) how do I convince Word/VBA to change these things back even if the cursor is NOT in the line of text? (I suspect this may be impossible as Word is creating 'hidden' intermediate styles, hence the style name for these styles won't match the pre-defined ones in the code (ie. the style name would be 'Section Heading + 14pt. Arial' instead of 'Section Heading')
b) Is there a way to select all instances of a particular style in VBA (ie. like using the 'Select all instances of this style' menu option from the Styles and Formatting toolbox) so that I can just cycle through each style name in code and select all instances of it before running the reset code?
I can provide a sample document with the code I have so far if needed.
Many thanks in advance for the torrent of help I'm potentially about to receive!