LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Help: 1004 Method 'Charts' of Object '_Global' failed

Hi all,
i have a code which sends data from a datagrid to MS Excel and then
plots the graph. I am copy pasting my code for it. The data gets
transferred from to Excel but once it is done i get the error message:
1004 Method 'Charts' of Object '_Global' failed. I dont get the plot.
However, at times the same code runs and a plot comes up. Any
Help ????? :-(

My code:
Dim iRowIndex As Integer
Dim iColIndex As Integer
Dim iRecordCount As Integer
Dim iFieldCount As Integer
Dim avRows As Variant
Dim excelVersion As Integer

Screen.MousePointer = vbHourglass

On Error GoTo expError

Adodc1.Recordset.MoveFirst

'--read all records into array
avRows = Adodc1.Recordset.GetRows()

'--Determine how many fields and records
iRecordCount = UBound(avRows, 2) + 1
iFieldCount = UBound(avRows, 1) + 1

'--Create reference variable for the spreadsheet
Set objExcel = GetObject("", "Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add

'--Ensures Excel remains visible if we switch to the active sheet
Set objTemp = objExcel

excelVersion = Val(objExcel.Application.Version)
If (excelVersion = 8) Then
Set objExcel = objExcel.ActiveSheet
End If



'--add data
With objExcel
For iRowIndex = 2 To iRecordCount + 1
For iColIndex = 1 To iFieldCount
.Cells(iRowIndex - 1, iColIndex).Value = avRows(iColIndex - 1,
iRowIndex - 2)
Next
Next
End With

objExcel.Cells(1, 1).CurrentRegion.EntireColumn.AutoFit
objExcel.Cells(1, 1).CurrentRegion.EntireRow.AutoFit
'Screen.MousePointer = vbDefault


'To plot the XY scatter after transferring data to Excel
Charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("H3")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
'ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!C2"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!C3"
ActiveChart.SeriesCollection(1).Name = "=""Detector 11"""
ActiveChart.SeriesCollection(2).XValues = "=Sheet1!C4"
ActiveChart.SeriesCollection(2).Values = "=Sheet1!C5"
ActiveChart.SeriesCollection(2).Name = "=""Raw UV Absorbance
Data"""
ActiveChart.SeriesCollection(3).XValues = "=Sheet1!C6"
ActiveChart.SeriesCollection(3).Values = "=Sheet1!C7"
ActiveChart.SeriesCollection(3).Name = _
"=""Differential Refractive Index data"""
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Light Scattering Data from DAWN
HELEOS of Wyatt Tech"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"Volume (mL)"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =
"Intensity"

End With
ActiveChart.SeriesCollection(3).Select
With Selection.Border
.ColorIndex = 46
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = 46
.MarkerForegroundColorIndex = 46
.MarkerStyle = xlCircle
.Smooth = True
.MarkerSize = 5
.Shadow = False
End With
ActiveChart.Legend.Select
Selection.AutoScaleFont = True
With Selection.Font
.Name = "Bookman Old Style"
.FontStyle = "Bold"
.Size = 9
End With
Selection.Left = 309
Selection.Top = 224
ActiveChart.SeriesCollection(3).Select
ActiveChart.PlotArea.Select
Selection.Left = 27
Selection.Top = 30
ActiveChart.Legend.Select
Selection.Height = 44
Selection.Left = 249
Selection.Width = 209
Selection.Height = 39
Selection.Top = 264
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.PlotArea.Select
Selection.Width = 309
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 1").ScaleHeight 1.08, msoFalse, _
msoScaleFromBottomRight
ActiveSheet.Shapes("Chart 1").ScaleHeight 1.09, msoFalse,
msoScaleFromTopLeft
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
Selection.Interior.ColorIndex = xlNone


Create_GIF
Picture1.Picture = LoadPicture("c:\Mychart.gif")
Picture1.Visible = True
Screen.MousePointer = vbDefault

Exit Sub


Thanks,
Anu

 
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
Runtime Error '1004' Method 'ActiveChart' of Object '_Global' failed [email protected] Excel Programming 6 January 30th 07 05:02 PM
Error 1004 Method 'Range' of object '_Global' failed bjwade62 Excel Programming 4 August 7th 06 03:57 PM
Run-time error '1004': Method 'Range' of object '_Global' failed Neild Excel Programming 0 February 12th 06 11:43 PM
Run-time error '1004': Method 'Range' of object '_Global' failed Tim Williams Excel Programming 2 February 12th 06 10:01 PM
Error 1004: Method 'Cells' of object '_Global' failed LT Excel Programming 2 October 31st 03 04:47 PM


All times are GMT +1. The time now is 10:31 AM.

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

About Us

"It's about Microsoft Excel"