Similar to my post 68178, I’ve been wondering what the Word experts out there consider their most useful word macros and customizations.
Cheers
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Useful Word Macros (All)
Similar to my post 68178, I’ve been wondering what the Word experts out there consider their most useful word macros and customizations.
Cheers
I wouldn’t dare to call myself a Word expert, but here are a few I find useful; all have been assigned to custom toolbar buttons in my setup.
Paste the contents of the clipboard as unformatted text:
Sub PasteUnformatted()
On Error Resume Next
Selection.PasteSpecial DataType:=wdPasteText
End Sub
Protect a document for forms without losing values already entered (useful during testing); the macro actually toggles protection mode. In recent versions of Word, the Protect Form button on the Forms toolbar does the same, but in Word 97 that button cleared form fields when turning on protection.
Sub SafeProtect()
On Error Resume Next
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
Else
ActiveDocument.Protect wdAllowOnlyFormFields, True
End If
End Sub
Paste the contents of the clipboard as a linked object, to be updated manually, inline with the text, and set line spacing to single. Meant for Excel tables and charts, for example. (If line spacing is exact, only a small part of an inline object will be displayed)
Sub PasteOLE()
On Error GoTo Exit_Sub
Selection.PasteSpecial Link:=True, DataType:=wdPasteOLEObject, Placement:=wdInLine
Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.InlineShapes(1).LinkFormat.AutoUpdate = False
Exit_Sub:
End Sub
Many of my macros are long and involved although the most commonly used one is temporary and overwritten whenever I need a macro for the day and don’t care to reuse it in the future. This allows me to create a macro that already has a button and keyboard shortcut assigned so I don’t waste time creating ways to run it.
Some of my more useful ‘longer term’ short macros are:
'====================================================== Sub NumberingAutoToHardcoded() 'Andrew Lockton - Chrysalis Design 'converts autonumbers to hard coded Dim iResp As Integer iResp = MsgBox("This macro converts automatic paragraph numbers to hard coded." _ & vbCr & "Click Yes to convert the entire document." & vbCr & _ "Click No to convert only the selected paragraphs." & vbCr & _ "Click Cancel to stop the macro.", _ vbYesNoCancel, "Delete Hard Numbers") If iResp = vbYes Then ActiveDocument.ConvertNumbersToText (wdNumberAllNumbers) ElseIf iResp = vbNo Then Selection.Range.ListFormat.ConvertNumbersToText (wdNumberAllNumbers) End If End Sub '==================================================== Sub NumberingDeleteHardcoded() 'Andrew Lockton - Chrysalis Design 'Only acts on selected paragraphs Dim iResp As Integer iResp = MsgBox("This macro will remove all hardcoded paragraph numbers " _ & vbCr & "from the SELECTED paragraphs. Click OK to continue.", _ vbOKCancel, "Delete Hard Numbers") If iResp = vbOK Then WordBasic.ToolsBulletsNumbers Replace:=0, Type:=1, Remove:=1 End If End Sub '========================================================== Sub AttachReportsTemplate() ' Macro created by Chrysalis Design Dim sTempPath As String sTempPath = Options.DefaultFilePath(wdUserTemplatesPath) With ActiveDocument .UpdateStylesOnOpen = False .AttachedTemplate = sTempPath & "Reports.dot" End With ActiveDocument.UpdateStyles End Sub
I’ve used your macros for Auto to Hardcoded and Delete Hardcoded and they’ve really come in handy. Auto to Hardcoded is something we use quite a bit (especially when we want to use PDF Maker to give us an Acrobat file with bookmarks — bookmarks don’t have numbers if you have an automatically numbered document).
Is there any way to confine to heading levels only if you’re doing a whole document (without selecting each heading separately)? For various reasons, sometimes we need to hardcode heading levels throughout a whole document but we don’t want bullets and other lists to become hardcoded. Wish I could figure it out myself, but I need the help. Thanks.
Something I find useful for letter templates etc. is a “macro button” for inserting the current date as a hard-coded line, rather than a field that keeps on updating. It also adds a superscripted date ordinal suffix – st, nd, rd, th.
The field code appears in the document as:
{MACROBUTTON VerboseDate [Double click this line to insert hard date]}
The macro code (not terribly optimized I’m afraid ) is:
Public Sub VerboseDate()
'
' VerboseDate Macro -
' Inserts a date at the current insersion point, in the form:
' "6th January, 2003"
' with the date ordinal formatted in superscript.
'
Dim MyDay, MyOrdinal
MyDay = Day(Date)
Select Case MyDay
Case 1, 21, 31
MyOrdinal = "st"
Case 2, 22
MyOrdinal = "nd"
Case 3, 23
MyOrdinal = "rd"
Case Else ' Other values.
MyOrdinal = "th"
End Select
Selection.TypeText Text:=MyDay
With Selection.Font
.Superscript = True
End With
Selection.TypeText Text:=MyOrdinal
With Selection.Font
.Superscript = False
End With
Selection.InsertDateTime DateTimeFormat:=" MMMM, yyyy", _
InsertAsField:=False
End Sub
Alan
I don’t like to type in some long syntaxes over and over again. So I put “wrappers” around them, allowing for some checks to prevent errors too. Like these two examples:
Public Function ExistsCDP(strName As Variant) As Boolean Dim prop As DocumentProperty ExistsCDP = False If Documents.Count < 1 Then Exit Function For Each prop In ActiveDocument.CustomDocumentProperties If UCase(prop.Name) = UCase(strName) Then ExistsCDP = True Exit For End If Next prop End Function Public Function GetValueOfCDP(strName As String) As String Dim prop As DocumentProperty GetValueOfCDP = "" If Documents.Count < 1 Then Exit Function For Each prop In ActiveDocument.CustomDocumentProperties If UCase(prop.Name) = UCase(strName) Then GetValueOfCDP = ActiveDocument.CustomDocumentProperties(prop.Name).Value Exit For End If Next End Function
Instead of strValue = ActiveDocument.CustomDocumentProperties(“MyCDP”).Value
I now use strValue = GetValueOfCDP(“MyCDP)
or If GetValueOfCDP(“MyCDP) = “Yes” Then
In my view this makes code more readable.
And – also important ! – testing if there’s at least 1 doc and looping through the collection prevent errors.
Sorry, I know this going back about a month and it is not a problem question but a general question.
Jan,
Your macro is extremely useful
– the question I have is what is the impact of using code directly against the wrapper – the speed of execution & the size of the document? Does it make any difference at all?
Thanks for the response.
Robie
Using the wrapper is slower, but the difference would only become noticeable if you had a macro that manipulates document properties in a loop that is executed thousands and thousands of times. If you need the value of a document variable occasionally, you won’t notice any difference at all.
The macro that consistenly saves me the most trouble is one developed with the help of some fellow loungers that cleans up those “Char Char” styles Word XP and 2003 like to insert:
http://www.windowsdevcenter.com/pub/a/wind…dex.html?page=2%5B/url%5D
And of course, not wanting to miss the chance for a shameless plug, my book is full of useful macros written by a variety of contributors. There’s a link below in my signature.
Cheers!
Here are some useful macros from a site called the “FREE GERMAN WORD SHOP”. They offer various word useful macros. They have created a single download that compiles all the macro’s on affer into a single download that is to be added to the STARTUP folder! (Just click on the “MACRO GALLERY” link in the second paragraph to get there!
Click here for Useful Word Macro’s
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.