4specs.com    4specs.com Home Page

Sub ResetStyles() Log Out | Topics | Search
Moderators | Register | Edit Profile

4specs Discussion Forum » Computers, the Internet and Networking » Sub ResetStyles() « Previous Next »

Author Message
Chris Grimm, CSI, CCS, SCIP, LEED AP BD+C
Senior Member
Username: chris_grimm_ccs_scip

Post Number: 337
Registered: 02-2014


Posted on Friday, January 08, 2016 - 01:12 am:   Edit PostDelete PostPrint Post

Have a document that doesn't follow its own style rules and you know they are good styles, but too many exceptions?

This 3-command macro instantly resets the whole document to just use the paragraph styles with no overrides. Including no character styles like colored English & metric units or some others that can get pretty wonky. The styles will still be available to your document, they are not being deleted. Just the overrides are removed.

Sub ResetStyles()
   Selection.WholeStory
   Selection.Font.Reset
   Selection.ParagraphFormat.Reset
End Sub


It is also great for when you have exported rtf's from e-SPECS that have tracked changes, and you like to be able to undelete paragraphs but you do not want annoying ? marks in front of every paragraph!

Here is a bit longer annotated version that also remembers the current position and text selection and then returns there:

Sub ResetStyles()
'derived from a comment at http://windowssecrets.com/forums/showthread.php/108724-Delete-All-Character-Styles-%28VBA-Word-2003%29
'same as Ctrl-A, Ctrl-space, Ctrl-Q, does whole document INSTANTLY!
'also using a tip from http://stackoverflow.com/questions/26650244/save-the-cursor-position-in-a-document-and-return-there-later-on
   Dim currentPosition As Range
   Set currentPosition = Selection.Range 'pick up current cursor position
   Selection.WholeStory
   Selection.Font.Reset
   Selection.ParagraphFormat.Reset
   currentPosition.Select 'return cursor to original position
End Sub


No guarantees, but worth testing it out? It is working great for me, pretty exciting in fact! My previous method was a bit slow, and with newer versions of Word it became slower and even started morphing neighboring paragraphs. Solved now I think! If you try it, let me know how it works for you.
Chris Grimm, CSI, CCS, SCIP, LEED AP BD+C
Senior Member
Username: chris_grimm_ccs_scip

Post Number: 338
Registered: 02-2014


Posted on Friday, January 08, 2016 - 01:23 am:   Edit PostDelete PostPrint Post

This is also useful and quite necessary after you attach a new style template, if the document has overrides, otherwise the new styles still do not all show up right.
Sheldon Wolfe
Senior Member
Username: sheldon_wolfe

Post Number: 890
Registered: 01-2003


Posted on Friday, January 08, 2016 - 01:37 pm:   Edit PostDelete PostPrint Post

Ctrl-spacebar resets selected text to the base styles.
Chris Grimm, CSI, CCS, SCIP, LEED AP BD+C
Senior Member
Username: chris_grimm_ccs_scip

Post Number: 339
Registered: 02-2014


Posted on Friday, January 08, 2016 - 04:40 pm:   Edit PostDelete PostPrint Post

Right, as noted. This runs that, preceded by Ctrl-A and then Ctrl-Q and returns you to where your cursor was.
Chris Grimm, CSI, CCS, SCIP, LEED AP BD+C
Senior Member
Username: chris_grimm_ccs_scip

Post Number: 340
Registered: 02-2014


Posted on Friday, January 08, 2016 - 06:06 pm:   Edit PostDelete PostPrint Post

This way you can make it one keystroke instead of 3 to clean a whole document, and you can reference it from other macros.
Chris Grimm, CSI, CCS, SCIP, LEED AP BD+C
Senior Member
Username: chris_grimm_ccs_scip

Post Number: 341
Registered: 02-2014


Posted on Friday, January 08, 2016 - 06:14 pm:   Edit PostDelete PostPrint Post

Two more lines that can be added to make sure tracked change deletions if any, and hidden text if any, also receive the resets:

   ActiveWindow.View.ShowRevisionsAndComments = True
   ActiveWindow.View.ShowHiddenText = True


I think these can be added anywhere before the 2 reset commands.
Sheldon Wolfe
Senior Member
Username: sheldon_wolfe

Post Number: 891
Registered: 01-2003


Posted on Friday, January 08, 2016 - 06:50 pm:   Edit PostDelete PostPrint Post

Sorry, Chris, didn't see it buried in a comment. And kudos to you for including comments!

Shift-F5 will rotate through the last five (?) cursor locations. Sometimes useful, but not often enough that I use it. A couple of Word versions ago, you could use it to return to your last editing point when you reopened a file. Now that was useful! It's always interesting to see what software companies change with each update.

I had a great macro; it would strip all formatting, attach my template file, set the margins, add headers and footers, delete blank lines, strip out double spaces after punctuation, and a couple other things. Guide specs have improved a lot since then, haven't used it for some time.
Chris Grimm, CSI, CCS, SCIP, LEED AP BD+C
Senior Member
Username: chris_grimm_ccs_scip

Post Number: 342
Registered: 02-2014


Posted on Friday, January 08, 2016 - 08:43 pm:   Edit PostDelete PostPrint Post

Cool! I learn new ones all the time, and Shift-F5 is my new one for the day. Sometimes it is by accident when I hit one and say "wow, it did that?". I stumbled upon Shift-F3 for converting case, a bit easier than the Alt key sequence I was doing (Alt, O, E, up/down arrows, Enter).

I hope you all have a great weekend!
Chris Grimm, CSI, CCS, SCIP, LEED AP BD+C
Senior Member
Username: chris_grimm_ccs_scip

Post Number: 344
Registered: 02-2014


Posted on Monday, January 11, 2016 - 06:13 pm:   Edit PostDelete PostPrint Post

I just noticed that in Word 2013 this is giving erratic results, regardless of whether I use a macro to do it or the built-in features like Ctrl-A, Ctrl-Space, Ctrl-Q, even though in older Word it does not.

In my documents there are tracked changes and hidden text. After I run the macro or use those keystrokes in 2013, then the moment I go into final view and turn off hidden text, it seems to strangely repeat some paragraphs any number of times, and it gets even stranger - if you type in one of the repeated paragraphs it simultaneously displays each typed character in all of them. I'm pretty certain it is a bug in Word because like I said it does that without even running any macro, after just using built-in keystrokes. In an older versions of Word I cannot even make it do that at all, it works flawlessly regardless of which method I use.

I will get it solved so 2013 and whatever other needed versions work OK for my group, but meanwhile I should point out that the usual wisdom applies, use at own risk. Whenever running automation it is good to try on limited files at first, and to keep a backup or work in a temporary copy. Things sometimes behave differently when used in a different environment than what has been tested and is being supported by your IT group and vendors they use -- that goes for any program. Especially when it comes to Word, it seems! It becomes increasingly frail with each new version.

Add Your Message Here
Post:
Username: Posting Information:
This is a public posting area. Enter your username and password if you have an account. Otherwise, enter your full name as your username and leave the password blank. Your e-mail address is optional.
Password:
E-mail:
Options: Automatically activate URLs in message
Action:

Topics | Last Day | Last Week | Tree View | Search | Help/Instructions | Program Credits Administration