Consulting

Results 1 to 5 of 5

Thread: Moving beyond a picture

  1. #1

    Question Moving beyond a picture

    I am an excel VBA expert but am new to Word programming. Please help.

    I have content stored in Excel and am writing it to a report in Word.
    -I insert a picture, convert it to a shape, and wrap the text "tight"
    -I add text, related to the picture.

    I end up with a picture on the left (it may be any size) with text (also may be of any length) . I move the cursor to the end of the text.

    When the picture is larger and/or the text is shorter, I end up needing a few additional lines inserted to move beyond the picture. Because both picture size and text lenght may vary, I can't simply insert a fixed number of lines. How can I move to exactly one line (row) past the picture and begin the process again?

    [VBA] With word_doc
    .ActiveWindow.Selection.EndKey unit:=wdStory, Extend:=wdMove
    For i = 1 To 30
    x = .ActiveWindow.Selection.Information(wdHorizontalPositionRelativeToPage)

    If "Some Property Changes that lets me know that I am past the picture" Then
    'Exit For 'Code to jump out of the loop and move on
    Else
    '// get the vertical position prior to pressing the down key.
    y = .ActiveWindow.Selection.Information(wdVerticalPositionRelativeToPage)

    '// press the down arrow
    .ActiveWindow.Selection.MoveDown unit:=wdLine, Extend:=wdMove

    '// above works great when there's text. but when you get to the last line, new lines
    '// will have to be inserted. If "y" doesn't change, send cursor to the end and press enter.

    If y = .ActiveWindow.Selection.Information(wdVerticalPositionRelativeToPage) Then
    .ActiveWindow.Selection.EndKey unit:=wdLine, Extend:=wdMove
    .ActiveWindow.Selection.TypeText (Chr(11))
    End If

    '// go to the beginning of the line. When it is at the beginning, "x" will adjust and kick us out of the loop
    .ActiveWindow.Selection.HomeKey unit:=wdLine, Extend:=wdMove

    End If

    Next i
    End With

    [/VBA]

    Other methods are welcome!

  2. #2
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    If your text is always related to the picture, I'd suggest using it as an inline shape in a two column table. Picture in left cell, text in right cell, borders all off... that would keep the relationships you want, I believe, and also allow you to disallow splitting rows at page breaks (which will be another issue, potentially.

  3. #3
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Also, I think working in a table with an inline shape is going to be a good bit easier concept to grasp as you're moving from Excel.

    There are a whole host of concepts unfamiliar to an Excel expert in what you're trying to do, such that even your question is kind of "wrong" (you don't really move "past" a shape, unless it is inline or in a frame, since shapes are in their own "story" in Word.

    Short answer: unless someone has another suggestion, I think utilizing a table is going to pay you the biggest bang for your buck in this case, and you're still going to learn plenty.

  4. #4
    Thanks Frosty,

    It certainly is a ton different moving through the document in Word than Excel....it requires a totally different way of thinking.

    No question that shapes are in a "story" world either. Inline isn't bad but once its converted, they're a bear.

    I like the suggestion of using 2 columns, but unfortunately, the formatting of wrapping text is critical. I've actually already made the "list-like" report in Excel, I am now using Word to get more of a document feel to things.

    I'll post it once I do figure out how to do this. Thanks!

  5. #5
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    The general way to do this is to do the reverse... Insert the text, format it properly, insert the picture using the range of the text you just inserted as your anchor range.

    You want to get out of the concept of lines and rows. All you should have is a paragraph and a shape.

    But layout with floating shapes can be very tricky. Can you post a sample of what you want? 3 pics with associated paragraphs laid out the way you think it should be laid out?

    I'm also confused what you mean about inline shapes being a bear once converted. Nothing is really converted.

    But without knowing the look of what you want, it's tough to give more than general advice, and unfortunately you've picked one of the areas where recording a macro to learn the right objects is probably going to steer you in the wrong direction.

Posting Permissions

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