Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Insert line of code with Find/Replace macro (MS Word 2003, XP SP2)

    Edited by HansV to insert <!t>[pre]<!/t> and <!t>[/pre]<!/t> tags

    Hello,

    I am trying to find a macro, that point to a folder full of text (.txt) files and do the following:

    1. Change: <FrameType Inline> to <FrameType Below>
    2. Add a carriage return and two spaces after <FrameType Below> and then insert the following code: <Float No>

    I have included a before and after version of the code below as well as the beginning of (I hope) a good macro.

    I am just not sure how to get the macro to insert a carriage return, add two spaces and insert <Float No>

    Any feedback provided is very much appreciated.
    Thanks in advance.

    Jim

    Before:
    <pre><FrameType Inline>
    <NSOffset 0.0">
    <BLOffset 0.0">
    <AnchorAlign Center>
    </pre>

    After:
    <pre><FrameType Below>
    <Float No>
    <NSOffset 0.0">
    <BLOffset 0.0">
    <AnchorAlign Center>
    </pre>

    <pre>Sub ReplaceInDoc(doc As Document)
    ActiveWindow.View.ShowFieldCodes = True
    With doc.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWildcards = True
    .Execute FindText:="<FrameType Inline>", _
    ReplaceWith:="<FrameType Below>", Replace:=wdReplaceAll

    End With
    ActiveWindow.View.ShowFieldCodes = False
    End Sub</pre>


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

    Re: Insert line of code with Find/Replace macro (MS Word 2003, XP SP2)

    You should use .MatchWildCards:=False here since you're not looking for variable text. You can then use
    <pre>... ReplaceWith:="<FrameType Below>^p ", ...
    </pre>

    ^p is the code for a paragraph mark in the Find what and Replace with boxes.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Insert line of code with Find/Replace macro (MS Word 2003, XP SP2)

    Hello Hans,

    Thanks for the quick reply.

    I am getting some sort of compile/syntax error and am not sure why.

    The carrots (< >) around FrameType Below need to be there, as seen here: <FrameType Below>

    Could that be causing the compile error? I noticed you left out the left carrot in your reply and added in a < to the code.
    What does that do?

    Finally, after the ^p - I need to add in the following text <Float No>
    Is that to be part of the original string in quotations or do I need to add in another string of quotations - to the macro code?

    Please see the attached screenshot.

    Thanks,

    Jim
    Attached Images Attached Images

  4. #4
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Insert line of code with Find/Replace macro (MS Word 2003, XP SP2)

    Hello again,

    I see a copy and paste error on my part and figued out that this website changed the carrot to a <

    Missed that part.

    Jim

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

    Re: Insert line of code with Find/Replace macro (MS Word 2003, XP SP2)

    You can add extra text within the quotes:
    <pre>... ReplaceWith:="<FrameType Below>^p <Float no>", ...
    </pre>

    I assume that the problem was in the e-mail notification? It tends to change "less than" and "greater than" characters to HTML coding. The display in the Lounge web page itself is always OK, as far as I can tell.

  6. #6
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Insert line of code with Find/Replace macro (MS Word 2003, XP SP2)

    Hi Hans,

    The macro works great. Thanks once again for your assistance.

    Regards,

    Jim

Posting Permissions

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