Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Canton, Ohio, USA
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    macro recording difficulty (VBA-Word XP)

    I am trying to record a macro to put me into the header of a letter on the second page and then change the date to a reference style. But when I am done recording, the destination gives me the path of the letter where I recorded the macro. I would like to know what code it takes to run that macro in any other letter that I open. I have zero knowledge about code, really. I just do my macros by recording them step by step.

    Thanks for helping in advance.

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

    Re: macro recording difficulty (VBA-Word XP)

    When you select Tools | Macro | Record New Macro, there's a dropdown labeled "Store macro in". This should be set to "All documents (Normal.dot)". The macro will be available in all documents, not just the one in which you recorded it.
    Attached Images Attached Images
    • File Type: png x.png (15.3 KB, 0 views)

  3. #3
    Lounger
    Join Date
    Jan 2001
    Location
    Canton, Ohio, USA
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro recording difficulty (VBA-Word XP)

    Hi Hans. I think I didn't explain very well what I meant. I want to make the macro work in every letter that needs the date changed, not just in the one that I recorded the macro in. I am sending the recorded macro below. Under "destination" is the path where the macro runs, but I want a destination to any letter I open no matter where it is located.

    Sub del()
    '
    ' del Macro
    ' Macro recorded 1/24/2008 by Johanna Murphy
    '
    Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
    Selection.Font.Bold = wdToggle
    If Selection.Font.Underline = wdUnderlineNone Then
    Selection.Font.Underline = wdUnderlineSingle
    Else
    Selection.Font.Underline = wdUnderlineNone
    End If
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=" "
    End Sub
    Sub DateStyleInHeader()
    '
    ' DateStyleInHeader Macro
    ' Macro recorded 1/25/2008 by Johanna Murphy
    '
    Application.OrganizerCopy Source:= _
    "Cocuments and SettingsjmApplication DataMicrosoftTemplatesNormal.dot" _
    , Destination:= _
    "G:Active DocsClientsGGenie Company, The 00014.00Green, Beverly 0217MEDIME LT Dr. Tully 02.doc" _
    , Name:="Date Ltr", Object:=wdOrganizerObjectStyles
    Selection.Style = ActiveDocument.Styles("Date Ltr")
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
    ActivePane.View.Type = wdOutlineView Then
    ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.MoveDown Unit:=wdLine, Count:=4
    Selection.HomeKey Unit:=wdLine
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Fields.add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "STYLEREF ""Date Ltr"" ", PreserveFormatting:=True
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End Sub

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

    Re: macro recording difficulty (VBA-Word XP)

    Try changing the instruction
    <code>
    Application.OrganizerCopy Source:= _
    "Cocuments and SettingsjmApplication DataMicrosoftTemplatesNormal.dot" _
    , Destination:= _
    "G:Active DocsClientsGGenie Company, The 00014.00Green, Beverly 0217MEDIME LT Dr. Tully 02.doc" _
    , Name:="Date Ltr", Object:=wdOrganizerObjectStyles
    </code>
    to
    <code>
    Application.OrganizerCopy Source:= "Normal.dot", Destination:= ActiveDocument.FullName, _
    Name:="Date Ltr", Object:=wdOrganizerObjectStyles
    </code>
    Instead of the literal path and name of the document, this uses ActiveDocument.FullName, which is the path and name of whatever happens to be the active document when you run the macro.

  5. #5
    Lounger
    Join Date
    Jan 2001
    Location
    Canton, Ohio, USA
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro recording difficulty (VBA-Word XP)

    You are definitely the KING in my eyes! It took me a bit to get all the spacing and whatever right, but it works wonderfully!

    Thank you!!!

Posting Permissions

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