How to create a toggle button for a toolbar command

V

VBMoron

Hi there,

First, I have never written a visual basic program or code or however it is
called, only recorded macros a few times and looked at the code (?) in the
Visual Basic Editor. Therefore, if anyone can help me, I'm afraid I will need
the complete code (or whatever) that I can just paste into VBA and - hey
presto!

I am working with WORD 2003 and found out, thanks to this discussion group,
that in order to use "select all instances" of a style I have to click "Keep
track of formatting". Well, I do hate "Keep track of formatting" because it
generates these stupid styles like "block text bold" etc. But, on the other
hand, I sometimes would like to find all instances where a certain style is
used in a document. For this purpose, I want to create a toggle button that
switches on and off the "Keep track of formatting" function.

I have recorded a macro to click "keep track of formatting" and it looks
like this:
Sub TrackFormatting()
'
' TrackFormatting Macro

' Application.DisplayStatusBar = True
Application.ShowWindowsInTaskbar = True
Application.ShowStartupDialog = False
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
.DisplayLeftScrollBar = False
.StyleAreaWidth = CentimetersToPoints(0)
.DisplayVerticalRuler = True
.DisplayRightRuler = False
.DisplayScreenTips = True
With .View
.ShowAnimation = True
.Draft = False
.WrapToWindow = False
.ShowPicturePlaceHolders = False
.ShowFieldCodes = False
.ShowBookmarks = False
.FieldShading = wdFieldShadingWhenSelected
.ShowTabs = False
.ShowSpaces = False
.ShowParagraphs = False
.ShowHyphens = False
.ShowHiddenText = False
.ShowAll = True
.ShowDrawings = True
.ShowObjectAnchors = False
.ShowTextBoundaries = True
.ShowHighlight = True
.DisplayPageBoundaries = True
.DisplaySmartTags = True
End With
End With
With Options
.ReplaceSelection = True
.AllowDragAndDrop = True
.AutoWordSelection = False
.INSKeyForPaste = False
.PasteSmartCutPaste = True
.AllowAccentedUppercase = False
.PictureEditor = "Microsoft Office Word"
.TabIndentKey = True
.Overtype = False
.AllowClickAndTypeMouse = False
.CtrlClickHyperlinkToOpen = True
.AutoKeyboardSwitching = False
.PictureWrapType = wdWrapMergeInline
.DisplayPasteOptions = False
.PromptUpdateStyle = True
.FormatScanning = True
.ShowFormatError = False
.SmartParaSelection = False
.SmartCursoring = True
End With
ActiveDocument.ClickAndTypeParagraphStyle = "Normal"
End Sub

Well, there seem to be quite a lot of things in this that probably are not
necessary for my purpose. And I can't identify which line refers to my "keep
track of formatting" function....
But, more important, I have no idea what to do now. I can assign a button to
this macro, but how can I make this button toggle between the two states, so
that I can click and unclick "keep track of formatting"? I am totally
helpless.
 
E

Edward

Or even more efficent way for writting toggle button code !
Sub TrackFormatting()
Options.FormatScanning = Not Options.FormatScanning
End Sub
 

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