Avatar of sahinman
sahinmanFlag for United States of America

asked on 

VB 6 & Excel Run-Time error '1004'

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

Visual Basic ClassicWindows OS

Avatar of undefined
Last Comment
sahinman
ASKER CERTIFIED SOLUTION
Avatar of oleggold
oleggold
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of oleggold
oleggold
Flag of United States of America image

Avatar of sahinman
sahinman
Flag of United States of America image

ASKER

Super! Solved my problem. I am impressed with the knowledge at this web site!!
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo