Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macros (Word Xp)

    I need some help building some macros. I need on that will remove all the field codes in a doc, i need one that will address page setup (margins and Layout), I need one to clear all the tabs in a doc and I need one to replace straight quotes with curly ones. HELP!!!

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

    Re: Macros (Word Xp)

    By "remove all the field codes", do you mean that you want to replace fields by their results ("freeze" them"), or to delete the fields including their results?

    What would you like to do with page setup?

    Here is a simple macro that will remove all tabstops in the main document. If you want to handle other parts of the document, such as headers and footers, it will need to be expanded.

    Sub RemoveTabs()
    Dim par As Paragraph
    For Each par In ActiveDocument.Paragraphs
    par.TabStops.ClearAll
    Next par
    End Sub

    Here is a macro that replaces single and double straight quotes by curly ones (again, in the main document):

    Sub Straight2Curly()
    Dim blnSetting As Boolean
    blnSetting = Options.AutoFormatAsYouTypeReplaceQuotes
    Options.AutoFormatAsYouTypeReplaceQuotes = True
    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Text = """"
    .Replacement.Text = """"
    .Execute Replace:=wdReplaceAll
    .Text = "'"
    .Replacement.Text = "'"
    .Execute Replace:=wdReplaceAll
    End With
    Options.AutoFormatAsYouTypeReplaceQuotes = blnSetting
    End Sub

  3. #3
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros (Word Xp)

    Thank you for the two macros and what I want to do with page setup is set the margins and the page layout and then the problem I have with the field codes is they come over from a doc assembly program and I need to remove them completly so that I can then go back and insert numbering.

  4. #4
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros (Word Xp)

    also, is there a way to modify the tab one to first clear the tabs and then set the standard tabs defaults which is every .5 ?

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

    Re: Macros (Word Xp)

    A general way to get an idea for macros is to record the actions you want. This will generally result in much more than you need, but you can edit the recorded macro afterwards. The following code to change page setup was recorded, I didn't edit it at all:

    With ActiveDocument.PageSetup
    .LineNumbering.Active = False
    .Orientation = wdOrientLandscape
    .TopMargin = CentimetersToPoints(2)
    .BottomMargin = CentimetersToPoints(2)
    .LeftMargin = CentimetersToPoints(2)
    .RightMargin = CentimetersToPoints(2)
    .Gutter = CentimetersToPoints(0)
    .HeaderDistance = CentimetersToPoints(1.25)
    .FooterDistance = CentimetersToPoints(1.25)
    .PageWidth = CentimetersToPoints(29.7)
    .PageHeight = CentimetersToPoints(21)
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    .SectionStart = wdSectionNewPage
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .VerticalAlignment = wdAlignVerticalTop
    .SuppressEndnotes = False
    .MirrorMargins = False
    .TwoPagesOnOne = False
    .BookFoldPrinting = False
    .BookFoldRevPrinting = False
    .BookFoldPrintingSheets = 1
    .GutterPos = wdGutterPosLeft
    End With

    It is easy to recognize which parts you need. Say that you just want to set page orientation and margins, this is what remains after removing superfluous instructions:

    With ActiveDocument.PageSetup
    .Orientation = wdOrientLandscape
    .TopMargin = CentimetersToPoints(2)
    .BottomMargin = CentimetersToPoints(2)
    .LeftMargin = CentimetersToPoints(2)
    .RightMargin = CentimetersToPoints(2)
    End With

    Here is a macro that removes fields in the main document:

    Sub RemoveFields()
    Dim n As Long
    For n = ActiveDocument.Fields.Count To 1 Step -1
    ActiveDocument.Fields(n).Delete
    Next n
    End Sub

    (I usually loop backwards when removing items from a collection; this avoids confusion)

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

    Re: Macros (Word Xp)

    The instruction to set the default tabstop distance can be found by recording a macro:

    ActiveDocument.DefaultTabStop = InchesToPoints(0.5)

  7. #7
    Star Lounger
    Join Date
    Aug 2002
    Location
    Orlando, Florida, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macros (Word Xp)

    Thanks.... You all always have the answers I need... <img src=/S/clever.gif border=0 alt=clever width=15 height=15>

Posting Permissions

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