Consulting

Results 1 to 4 of 4

Thread: Something is wrong with my macro

  1. #1
    VBAX Newbie
    Joined
    Mar 2014
    Posts
    3
    Location

    Something is wrong with my macro

    Hi folks, I am recording macros in Word as an introduction to the language. I made this one this morning but it doesn't work for some reason. It's designed to insert a placeholder at the start of every paragraph of a certain style.

    Sub insertplaceholder3()
    '
    ' insertplaceholder3 Macro
    '
    '
        Selection.Find.ClearFormatting
        Selection.Find.Style = ActiveDocument.Styles("Customer Question Body Copy" _
            )
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
        Selection.MoveDown Unit:=wdParagraph, Count:=1
        Selection.TypeText Text:="<<response placeholder>>"
        Selection.TypeParagraph
        Selection.MoveUp Unit:=wdLine, Count:=1
        Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
        Selection.Style = ActiveDocument.Styles("Body Copy")
        Options.DefaultHighlightColorIndex = wdYellow
        Selection.Range.HighlightColorIndex = wdYellow
    End Sub
    When I run the macro in Word, VBA pops up with an error message that says 'Expected: line number or label statement or end of statement.'

    Is there an easy way to fix this?

    Thanks
    G
    Last edited by SamT; 04-23-2014 at 08:02 AM. Reason: Changed quote tags to Code tags (# icon)

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location

    try changing
        Selection.Find.Style = ActiveDocument.Styles("Customer Question Body Copy" _ 
    )
    to
        Selection.Find.Style = ActiveDocument.Styles("Customer Question Body Copy")
    Should not make a difference, but

    In any case, this post will bump you up the list, best I can do for you
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Maybe

    Sub insertplaceholder3()
        With Selection
        
            .ClearFormatting
            .Style = ActiveDocument.Styles("Customer Question Body Copy")
            .MoveDown Unit:=wdParagraph, Count:=1
            .TypeText Text:="<<response placeholder>>"
            .TypeParagraph
            .MoveUp Unit:=wdLine, Count:=1
            .MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
            .Style = ActiveDocument.Styles("Body Copy")
            .Range.HighlightColorIndex = wdYellow
        End With
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Newbie
    Joined
    Mar 2014
    Posts
    3
    Location
    Thanks for the suggestions folks, these didn't work, but I tried it again by saving the macro in the document rather than Normal.dotm, which removed the problem.
    Cheers
    George

Posting Permissions

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