C
chris.w.news
Hi,
I'm trying to using VBA to take a description (the caption) from an
Excel document and place it under a JPEG image in Word. I originally
tried to do this by just using TypeText a paragraph under the image but
as it would always put it on the next page, I decided to use a Textbox.
My code is as follows:
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add
With wdApp.Selection
'Set page as landscape
.PageSetup.Orientation = wdOrientLandscape
'Align as Centre
.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter
.TypeParagraph
' Insert as an InlineShape
Set objShape = myDoc.InlineShapes.AddPicture(imageAddress)
imagePosition =
objShape.Range.Information(wdVerticalPositionRelativeToPage)
' Resize the image
If objShape.Height > InchesToPoints(4) Then
objShape.Height = InchesToPoints(4)
objShape.ScaleWidth = objShape.ScaleHeight
End If
.TypeParagraph
Set txtBox =
myDoc.Shapes.AddTextbox(msoTextOrientationHorizontal, 235,
imagePosition, 330, 60)
txtBox.TextFrame.TextRange.Text = docDate & " " & docRef & ": "
& description
txtBox.ZOrder (msoBringToFront)
txtBox.Line.Visible = msoFalse
End With
I've tried resizing the image to a smaller size and using the image
position to place the text but whatever method I try it always places
the text box on a second page and never directly underneath.
How can I get the text to go directly under the photo and on the same
page. The images are generally all 640 x 480 pixels.
Thanks for any help,
Chris
I'm trying to using VBA to take a description (the caption) from an
Excel document and place it under a JPEG image in Word. I originally
tried to do this by just using TypeText a paragraph under the image but
as it would always put it on the next page, I decided to use a Textbox.
My code is as follows:
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add
With wdApp.Selection
'Set page as landscape
.PageSetup.Orientation = wdOrientLandscape
'Align as Centre
.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter
.TypeParagraph
' Insert as an InlineShape
Set objShape = myDoc.InlineShapes.AddPicture(imageAddress)
imagePosition =
objShape.Range.Information(wdVerticalPositionRelativeToPage)
' Resize the image
If objShape.Height > InchesToPoints(4) Then
objShape.Height = InchesToPoints(4)
objShape.ScaleWidth = objShape.ScaleHeight
End If
.TypeParagraph
Set txtBox =
myDoc.Shapes.AddTextbox(msoTextOrientationHorizontal, 235,
imagePosition, 330, 60)
txtBox.TextFrame.TextRange.Text = docDate & " " & docRef & ": "
& description
txtBox.ZOrder (msoBringToFront)
txtBox.Line.Visible = msoFalse
End With
I've tried resizing the image to a smaller size and using the image
position to place the text but whatever method I try it always places
the text box on a second page and never directly underneath.
How can I get the text to go directly under the photo and on the same
page. The images are generally all 640 x 480 pixels.
Thanks for any help,
Chris