Results 1 to 15 of 15
  1. #1
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Useful Word Macros (All)

    Similar to my <post#=68178 >post 68178 </post#>, I've been wondering what the Word experts out there consider their most useful word macros and customizations.

    Cheers

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Useful Word Macros (All)

    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

    <img src=/w3timages/blueline.gif width=33% height=2>

    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

    <img src=/w3timages/blueline.gif width=33% height=2>

    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

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Useful Word Macros (All)

    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:
    <pre>'============================================ ==========
    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</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Useful Word Macros (All)

    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 <img src=/S/blush.gif border=0 alt=blush width=15 height=15>) is:
    <code>
    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
    </code>


    Alan

  5. #5
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Useful Word Macros (All)

    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:

    <pre>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 </pre>


  6. #6
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Useful Word Macros (All)

    Hmmm what do you mean by long syntaxes?

  7. #7
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Useful Word Macros (All)

    Instead of strValue = ActiveDocument.CustomDocumentProperties("MyCDP").V alue
    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.

  8. #8
    Star Lounger
    Join Date
    Jan 2005
    Location
    Linthicum, Maryland, USA
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Useful Word Macros (All)

    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.

  9. #9
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Useful Word Macros (All)

    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 <img src=/S/cool.gif border=0 alt=cool width=15 height=15> <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> - 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
    Thanks.
    Robie

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Useful Word Macros (All)

    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.

  11. #11
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Useful Word Macros (All)

    Couldn't have said it better myself... <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

  12. #12
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Useful Word Macros (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
    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!

  13. #13
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Useful Word Macros (All)

    Hans, even if you wouldn't, I would certainly call you an expert, and I'm sure many others around here would agree.

  14. #14
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Useful Word Macros (All)

    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
    Regards,
    Rudi

  15. #15
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Useful Word Macros (All)

    Thanks Rudi. There's some interesting looking stuff there. Also interesting is the use of the term "draw & drop" instead of "drag & drop". Maybe that's how it translates literally to German?

    Alan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •