Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Run time error '1004'

Hi ,

The following code is running fine for the first time, but when i run it for
the second time, the following error occurs.

Run time error '1004' Method 'Charts' of object '_Global' failed.

the errors occurs at Line

" Charts.Add"

'------------------------------------------------------Option Explicit

Dim xlobj As Excel.Application

Dim xlwkbk As Excel.Workbook

Dim xlSheet As Excel.Worksheet

Private Sub command1_Click()

-

On Error GoTo erb

Set xlobj = CreateObject("Excel.Application")

Set xlwkbk = xlobj.Workbooks.Add

Set xlSheet = xlwkbk.Worksheets.Add

xlSheet.Name = "A1"

xlSheet.Cells(3, 3) = "a"

xlSheet.Cells(3, 4)= "b"

xlSheet.Cells(3, 5)="c"

xlSheet.Cells(4, 3) = 10

xlSheet.Cells(4, 4)= 12

xlSheet.Cells(4, 5)= 11



xlobj.Application.Visible = True

xlobj.Parent.Windows(1).Visible = True

Charts.Add



ActiveChart.ChartType = xlColumnClustered

ActiveChart.SetSourceData

Source:=Sheets("A1").Range("C3:E4"), PlotBy:= xlRows

ActiveChart.Location Whe=xlLocationAsObject,

Name:="A1"

With ActiveChart

..HasTitle = True

..ChartTitle.Characters.Text = "PQR% OVERALL"

..Axes(xlCategory, xlPrimary).HasTitle = True

..Axes(xlCategory,

xlPrimary).AxisTitle.Characters.Text = "Companies"

..Axes(xlValue, xlPrimary).HasTitle = True

..Axes(xlValue,

xlPrimary).AxisTitle.Characters.Text = "PQR%"

End With

end sub

Can some help please.

TIA,

Gary


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run time error '1004'

If this is Excel VBA then I'm not clear why you're using
the excel object method. Worked for me.....

Option Explicit
Dim xlwkbk As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Private Sub Create()
Set xlwkbk = Workbooks.Add
Set xlSheet = xlwkbk.Worksheets.Add
xlSheet.Name = "A1"
xlSheet.Cells(3, 3) = "a"
xlSheet.Cells(3, 4) = "b"
xlSheet.Cells(3, 5) = "c"
xlSheet.Cells(4, 3) = 10
xlSheet.Cells(4, 4) = 12
xlSheet.Cells(4, 5) = 11
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData _
Source:=Sheets("A1").Range("C3:E4"), _
PlotBy:=xlRows
ActiveChart.Location _
Whe=xlLocationAsObject, _
Name:="A1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = _
"PQR% OVERALL"
.Axes(xlCategory, _
xlPrimary).HasTitle = True
.Axes(xlCategory, _
xlPrimary).AxisTitle.Characters.Text _
= "Companies"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, _
xlPrimary).AxisTitle.Characters.Text = "PQR%"
End With
End Sub

Patrick Molloy
Microsoft Excel MVP




-----Original Message-----
Hi ,

The following code is running fine for the first time,

but when i run it for
the second time, the following error occurs.

Run time error '1004' Method 'Charts' of

object '_Global' failed.

the errors occurs at Line

" Charts.Add"

'------------------------------------------------------

Option Explicit

Dim xlobj As Excel.Application

Dim xlwkbk As Excel.Workbook

Dim xlSheet As Excel.Worksheet

Private Sub command1_Click()

-

On Error GoTo erb

Set xlobj = CreateObject("Excel.Application")

Set xlwkbk = xlobj.Workbooks.Add

Set xlSheet = xlwkbk.Worksheets.Add

xlSheet.Name = "A1"

xlSheet.Cells(3, 3) = "a"

xlSheet.Cells(3, 4)= "b"

xlSheet.Cells(3, 5)="c"

xlSheet.Cells(4, 3) = 10

xlSheet.Cells(4, 4)= 12

xlSheet.Cells(4, 5)= 11



xlobj.Application.Visible = True

xlobj.Parent.Windows(1).Visible = True

Charts.Add



ActiveChart.ChartType = xlColumnClustered

ActiveChart.SetSourceData

Source:=Sheets("A1").Range("C3:E4"), PlotBy:= xlRows

ActiveChart.Location Whe=xlLocationAsObject,

Name:="A1"

With ActiveChart

..HasTitle = True

..ChartTitle.Characters.Text = "PQR% OVERALL"

..Axes(xlCategory, xlPrimary).HasTitle = True

..Axes(xlCategory,

xlPrimary).AxisTitle.Characters.Text = "Companies"

..Axes(xlValue, xlPrimary).HasTitle = True

..Axes(xlValue,

xlPrimary).AxisTitle.Characters.Text = "PQR%"

End With

end sub

Can some help please.

TIA,

Gary


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
run time error 1004 brownti via OfficeKB.com Excel Discussion (Misc queries) 5 February 14th 07 04:50 PM
run time error 1004 Louise Excel Discussion (Misc queries) 1 January 18th 07 11:11 PM
Run Time Error '1004' Carpie Excel Discussion (Misc queries) 3 June 5th 06 07:04 PM
Run time error 1004 Potoroo Excel Discussion (Misc queries) 2 December 30th 05 02:42 AM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM


All times are GMT +1. The time now is 12:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"