Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel automation pastespecial getting OLE exception

BugZap13

Programmer
Dec 2, 2013
38
US
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.

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
 

Part and Inventory Search

Sponsor

Back
Top