I'm working on a project were I run a report and when the work is done I want Excel to select and copy a range then paste as picture in a new Word document.
As the size of the image is relatively big for a portrait orientation, I want Word to change it to Landscape mode. And that's my problem. Can someone help?
Sub PasteAsPicture()
Dim objWord, objDoc As Object
With Workbooks("Workbook Name").Sheets("Sheet Name")
.Range("A1:S40").CopyPicture Appearance:=xlScreen, Format:=xlPicture
End With
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
With objWord
.Visible = True
.ActiveDocument.PageSetup.Orientation = wdOrientLandscape
.Selection.Paste
.Selection.TypeParagraph
End With
End Sub
Without a reference to the Word object library, the constant wdOrientLandscape
will have no value in Excel VBA, so either:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.