I am trying to copy cells from one workbook to a second workbook. At the line with the "PasteSpecial" I am getting:
"OLE Dispatch exception code 0 from Microsoft Excel: Unable to get the PasteSpecial property of the range class."
I have reviewed various threads specifically this one (1093592) which did a select then the copy. Below is a basic program I put together to test this which illustrated the problem. If it matters, I am using Excel 2016. TIA for any help.
"OLE Dispatch exception code 0 from Microsoft Excel: Unable to get the PasteSpecial property of the range class."
I have reviewed various threads specifically this one (1093592) which did a select then the copy. Below is a basic program I put together to test this which illustrated the problem. If it matters, I am using Excel 2016. TIA for any help.
Code:
#DEFINE xlPasteAll -4101
#DEFINE xlNone -4142
PRIVATE poExcel,poModel,poWorkBook,pnRow
poExcel = CREATEOBJECT("Excel.Application")
poExcel.Visible = .T.
poModel = .NULL.
poWorkBook = .NULL.
*
lcModel = 'd:\model.xlsx'
IF FILE(lcModel)
poModel = poExcel.Workbooks.Open(lcModel)
ELSE
poModel= poExcel.Workbooks.Add()
poModel.SaveAs(lcModel)
ENDIF
*
lcGMS = "d:\GMS-" + DTOS(DATE()) + '.xlsx'
IF FILE(lcGMS)
ERASE (lcGMS)
ENDIF
poWorkBook=poExcel.Workbooks.Add()
poWorkBook.SaveAs(lcGMS)
*
poModel.Activesheet.Range("A1:BZ1").Copy
poWorkBook.Activesheet.Range("A10:BZ10").PasteSpecial(xlPasteAll,xlNone,.F.,.F.)
*
poExcel.Quit