troubleshooting Question

VB 6 & Excel Run-Time error '1004'

Avatar of sahinman
sahinmanFlag for United States of America asked on
Visual Basic ClassicWindows OS
5 Comments1 Solution8872 ViewsLast Modified:
I have the following VB 6 code (w/Office 2000) which is to load an XLS file and create a chart of the data in column F, rows 10 to 85. When I launch the program and run the SubProgram once it works, but if I try to run it a second time I get the following error message:
Run-time error '1004' Method 'Charts' of object '_Applicaiton' failed. What am I missing??

Private Sub Form_Click()
Dim xlApp As Excel.Application
Dim xlWkb As Excel.Workbook
Dim xlWrkSht As Excel.Worksheet
Dim xlChart As Excel.Chart
Dim xlRange As Excel.Range

Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = True
Set xlWkb = xlApp.Workbooks.Open("C:\Summary.xls")
Set xlWrkSht = xlWkb.Sheets(1)
Set xlRange = xlWrkSht.Range("F10:F85")
Set xlChart = Application.Charts.Add
With xlChart
    .ChartType = xlLine
    .SetSourceData Source:=xlRange
    .Location Where:=xlLocationAsObject, Name:=xlWrkSht.Name
End With

xlApp.Application.SaveWorkspace "C:\Summary1.xls"
xlApp.Workbooks.Close
Set xlRange = Nothing
Set xlChart = Nothing
Set xlWrkSht = Nothing
Set xlWkb = Nothing
xlApp.Quit
Set xlApp = Nothing

End Sub

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros