Method 'Cells' of object '_Global' failed

A

Ashish Kanoongo

I am generating a excel work sheet with various row and columns and filled with formulas and cell values.

When I tried thies application first time, it works perfect, the next time i get this error:

Method 'Cells' of object '_Global' failed

I have declare following code at the declaration section
Dim ExcelApp As Excel.Application
Dim ExcelSht As Excel.Worksheet
Dim ExcelWkb As Excel.Workbook

Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Visible = True
Set ExcelWkb = ExcelApp.Workbooks.Add
Set ExcelSht = ExcelWkb.Worksheets(1)
ExcelSht.Visible = xlSheetVisible
ExcelSht.PageSetup.PrintGridlines = True
ExcelSht.PageSetup.Orientation = xlLandscape
ExcelSht.PageSetup.CenterHeader = "Distrubution Sheet"
Billing_Advance ' Function for calucation and genrates values in row and column

At the end of the code I hv given following code

Set ExcelSht = Nothing

ExcelWkb.Close True
Set ExcelWkb = Nothing

ExcelApp.Quit
Set ExcelApp = Nothing

set ExcelWkb = nothing
set ExcelSht = nothing
set ExcelApp = nothing

But nothing happens

Let me know whats wrong I am doing or how do I handle this?


Ashish
 
T

TC

Er: ask in an Excel newsgroup? And perhaps >not< in HTML (which opens the reader to various HTML related attacks)

HTH,
TC


I am generating a excel work sheet with various row and columns and filled with formulas and cell values.

When I tried thies application first time, it works perfect, the next time i get this error:

Method 'Cells' of object '_Global' failed

I have declare following code at the declaration section
Dim ExcelApp As Excel.Application
Dim ExcelSht As Excel.Worksheet
Dim ExcelWkb As Excel.Workbook

Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Visible = True
Set ExcelWkb = ExcelApp.Workbooks.Add
Set ExcelSht = ExcelWkb.Worksheets(1)
ExcelSht.Visible = xlSheetVisible
ExcelSht.PageSetup.PrintGridlines = True
ExcelSht.PageSetup.Orientation = xlLandscape
ExcelSht.PageSetup.CenterHeader = "Distrubution Sheet"
Billing_Advance ' Function for calucation and genrates values in row and column

At the end of the code I hv given following code

Set ExcelSht = Nothing

ExcelWkb.Close True
Set ExcelWkb = Nothing

ExcelApp.Quit
Set ExcelApp = Nothing

set ExcelWkb = nothing
set ExcelSht = nothing
set ExcelApp = nothing

But nothing happens

Let me know whats wrong I am doing or how do I handle this?


Ashish
 
T

Tushar Mehta

What is the line of code that generates that error? My guess is it is
none that you've shared.

Do you by any chance have an unqualified reference to the Cells
property, as in Cells(x,y) rather than
{some worksheet object}.Cells(x,y)?

--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top