SimonGeoghegan
Board Regular
- Joined
- Nov 5, 2013
- Messages
- 68
Hi All,
I have some code which I found from "spreadsheetguru" - and amended for my own specification. This copies an excel range into a word template as a picture/image. This works well, but I'm trying to understand if there is any snippets of code that I can add in order to:
Resize the width and height of the image once in Word
Paste the image onto a particular page within the template.
At the moment, it pastes the image fine but at the very beginning of the word document.
Any help greatly appreciated!
Thanks,
Simon
I have some code which I found from "spreadsheetguru" - and amended for my own specification. This copies an excel range into a word template as a picture/image. This works well, but I'm trying to understand if there is any snippets of code that I can add in order to:
Resize the width and height of the image once in Word
Paste the image onto a particular page within the template.
At the moment, it pastes the image fine but at the very beginning of the word document.
Any help greatly appreciated!
Thanks,
Simon
VBA Code:
Sub CGReport()
'PURPOSE: Copy/Paste An Excel Table Into a New Word Document
'NOTE: Must have Word Object Library Active in Order to Run _
(VBE > Tools > References > Microsoft Word 12.0 Object Library)
'SOURCE: www.TheSpreadsheetGuru.com
Dim tbl As Excel.Range
Dim WordApp As Word.Application
Set WordApp = CreateObject("word.Application")
Dim WordTable As Word.Table
Dim strFile As String
strFile = "c:\Users\sgeoghegan\Desktop\Clinical Governance Reporting\Hospital Clinical Governance Report TEMPLATE V2.docm"
Dim myDoc As Word.Document
Dim HospitalName As String
HospitalName = ThisWorkbook.Worksheets("Brain").Range("L2")
Dim ReportingMonth As String
ReportingMonth = ThisWorkbook.Worksheets("Brain").Range("AV6")
Dim RiskManPopulationDate As String
ReportingMonth = ThisWorkbook.Worksheets("Brain").Range("L3")
'Optimize Code
Application.ScreenUpdating = False
Application.EnableEvents = False
'Open Word Document
WordApp.Documents.Open strFile
WordApp.Visible = True
'Copy Range from Excel
Set tbl = ThisWorkbook.Worksheets("Summary Page").Range("B5:AX50")
'Create a New Document
Set myDoc = WordApp.Documents(strFile)
'Copy Excel Table Range
tbl.CopyPicture
'Paste Table into MS Word
myDoc.Paragraphs(1).Range.PasteSpecial
EndRoutine:
'Optimize Code
Application.ScreenUpdating = True
Application.EnableEvents = True
'Clear The Clipboard
Application.CutCopyMode = False
End Sub