Baravelli
08-04-2011, 07:01 AM
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?
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
Other methods are welcome!
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?
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
Other methods are welcome!