Hello,
This is a great website and resource and I wanted to thank everyone for their contributions. I am receiving a run-time error 1004 "CopyPicture method of range failed" when trying to run a macro multiple times. From internet research I created a macro to copy a range of cells and paste the data to Word as a picture. The code also opens a template word document to do this and then saves the file as a specific name. The macro will work some of the time and then out of nowhere I will get the error. Using Debug will point specifically to "Sheets("New Form").Range("$A$1:$J$51").CopyPicture". Can anyone help me fix the coding to resolve the error that I receive?
This is a great website and resource and I wanted to thank everyone for their contributions. I am receiving a run-time error 1004 "CopyPicture method of range failed" when trying to run a macro multiple times. From internet research I created a macro to copy a range of cells and paste the data to Word as a picture. The code also opens a template word document to do this and then saves the file as a specific name. The macro will work some of the time and then out of nowhere I will get the error. Using Debug will point specifically to "Sheets("New Form").Range("$A$1:$J$51").CopyPicture". Can anyone help me fix the coding to resolve the error that I receive?
Code:
Sub CapitalAccountStatements()
Dim objWord
Dim objDoc
Dim objSelection
Set objWord = CreateObject("Word.Application")
'Template Location
Set objDoc = objWord.Documents.Open("C:\Users\jlichtman\Desktop\Temp Print\Test\Copy to Word\Test Word.docx")
objWord.Visible = True
'Copy Range & Paste
Sheets("New Form").Select
Sheets("New Form").Range("$A$1:$J$51").CopyPicture
Set objSelection = objWord.Selection
objSelection.TypeParagraph
objSelection.Paste
'Save As Sourcing
Dim FName As String
Dim FPath As String
FPath = Sheets("New Form").Range("M7").Text
FName = Sheets("New Form").Range("M6").Text
objDoc.SaveAs Filename:=FPath & "\" & FName
objWord.Quit
End Sub