• Macro to search for text box (Word 2000)

    Author
    Topic
    #417401

    I’ve got about 500 documents, all including a text box along the left side of the page. I’ve figured out a macro to select the text box, reposition it and add another one above it; however, on some documents the macro won’t run because of the text box number. In looking at my code, depending on which document I recorded the macro on, it says “Text Box 2” or 3 or 20, etc. I’ve tried deleting the number and just having it search for “Text Box” but that doesn’t work either. Is there some other code I can start with that will select that text box, no matter what the number of it is?

    Thanks,

    Viewing 0 reply threads
    Author
    Replies
    • #936425

      Is this text box the only one in the document when you start the macro? If so, you can use code like this:

      Dim sh As Shape
      For Each sh In ActiveDocument.Shapes
      If sh.Type = msoTextBox Then
      sh.Top = 144 ‘ points

      Exit For
      End If
      Next sh

      If the document may already contain more than one text box, you will need to have a way to identify the one you want to move.

      • #936435

        Hans,

        Are the 3 dots where the rest of my macro would go?

        • #936443

          Yes, any other code to manipulate the text box should go there.

          • #936473

            Hans,

            I put code for that particular text box in where it should have gone but when running it – it didn’t do anything with that text box then errored on my next piece of code. It’s entirely possible I missed something or put something in the wrong place. If I post the document could you take a look at my original code?

            • #936475

              Posting your document is a good idea. It should be less than 100 KB (zip it if it’s too large). Remove sensitive information or replace it with dummy text.

            • #936476

              Heres the file. The first page was one doc and the second page was another doc but I combined for the post. The second one as a standalone document works with my original macro but the first one does not. There will never be 2 files together to have to search for the second text box.

              Thanks much!

            • #936483

              Does the macro in the attached document work for you?

            • #936503

              Hans, where in the top part would I say to resize the large text box to 7″ high rather than 8.04?

            • #936563

              Add the line

              .Height = InchesToPoints(7)

              below the lines that set the Top and Left position.

            • #936695

              Hans,

              I cannot thank you enough for your help. It is MUCH appreciated.
              thankyou

    Viewing 0 reply threads
    Reply To: Macro to search for text box (Word 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: