ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Methode 'Cells' of object '_Worksheet' failed (https://www.excelbanter.com/excel-programming/320908-methode-cells-object-_worksheet-failed.html)

Filips Benoit

Methode 'Cells' of object '_Worksheet' failed
 
Dear All,

Creating an invoice in excel from Access.adp with SQL-server-data.
I have about 10 simular functions to create invoices for other clients,
never had this problem!

There are 2 types of orders in 1 invoice.
First i count the orders for each type.
Then i open excel-template-invoice and write date for each type if present.

Set xlApp = CreateObject("Excel.Application")
Set WB = xlApp.Workbooks.Open(strPath & "\" & strFile)
Set WS = WB.Sheets(1)
xlApp.Visible = True

The 2 parts of code for each ordertype are nearly the same.
If there only are orders of type 1 there are no problems, the invoice is
correctly created and saved.

BUT, the code for type2 triggers error -2147221080 Methode 'Cells' of
'_Worksheet' failed.

This is the codeline that trigger the error
MsgBox iRow ' shows a correctly the rowNr before the error
WS.Cells(iRow, 1).Value = "Tokyo"

After a hole day of looking, testing, stress i'm totally stuck!

Please HELP!

Filip



Jan Karel Pieterse

Methode 'Cells' of object '_Worksheet' failed
 
Hi Filips,

This is the codeline that trigger the error
MsgBox iRow ' shows a correctly the rowNr before the error
WS.Cells(iRow, 1).Value = "Tokyo"

After a hole day of looking, testing, stress i'm totally stuck!


Are you sure Sheets(1) is a worksheet and not some other sheet, like a
chart or a dialogsheet?

Or maybe Sheets(1) is protected?

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com



All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com