PDA

View Full Version : VBA to copy from Excel as image and paste in Word



jenndan
03-05-2020, 06:14 PM
I found some code that basically does what I need, but I need it to paste in as a picture. What needs to change in Excel 2016 for that? Thank you for any help!


Sub CopyWorksheetsToWord()
Dim wdApp As Word.Application, wdDoc As Word.Document, ws As Worksheet
Application.ScreenUpdating = False
Application.StatusBar = "Creating new document..."
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Add
For Each ws In ActiveWorkbook.Worksheets
Application.StatusBar = "Copying data from " & ws.Name & "..."
ws.UsedRange.Copy
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.InsertParagraphAfter
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Paste
Application.CutCopyMode = False
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.InsertParagraphAfter
If Not ws.Name = Worksheets(Worksheets.Count).Name Then
With wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range
.InsertParagraphBefore
.Collapse Direction:=wdCollapseEnd
.InsertBreak Type:=wdPageBreak
End With
End If
Next ws
Set ws = Nothing
Application.StatusBar = "Cleaning up..."
With wdApp.ActiveWindow
If .View.SplitSpecial = wdPaneNone Then
.ActivePane.View.Type = wdNormalView
Else
.View.Type = wdNormalView
End If
End With
Set wdDoc = Nothing
wdApp.Visible = True
Set wdApp = Nothing
Application.StatusBar = False
End Sub

Dave
03-05-2020, 06:57 PM
jenndan I just replied to this same request at Mr. Excel. Please review the forum guidelines at both sites re. cross posting. Dave

macropod
03-05-2020, 07:59 PM
Cross-posted at:
https://www.excelforum.com/excel-programming-vba-macros/1308587-vba-to-copy-from-excel-as-image-and-paste-in-word.html
https://www.mrexcel.com/board/threads/vba-to-copy-from-excel-as-image-and-paste-in-word.1126433 (http://www.vbaexpress.com/forum/showthread.php?66938-VBA-to-copy-from-Excel-as-image-and-paste-in-Word)
Please read VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3