HI,
I have the following piece of code in Access.
Dim objSht As excel.Worksheet
Dim objexcel As New excel.Application
Dim wbexcel As excel.Workbook
Dim wbExists As Boolean
Dim objRange As excel.Range
Dim isFileAlreadyPresent As Boolean
Set objexcel = CreateObject("excel.Application")
Set wbexcel = objexcel.Workbooks.Open(file_name)
Set objSht = wbexcel.Worksheets(table_name)
isFileAlreadyPresent = True
objSht.Activate
objSht.Range(Range_para).Select
Charts.Add
ActiveChart.chartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets(table_name).Range(Range_para), _
PlotBy:= xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
ActiveChart.HasLegend = False
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.text = CHart_title
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
If isFileAlreadyPresent = True Then
wbexcel.Save
Else
wbexcel.SaveAs (file_name)
End If
objexcel.Visible = True
wbexcel.Close
I am having two problems. Every second time I run the code I get an run time error 462 (The remote server machine does not exist or is unavailable ) at line Charts.add.
I know that I am not using the objexcel property correctly but I am not sure where I am going wrong.
Also after the code is run, even though excel closes. The process runs in the background and this interferes with the next run of the code. How do I close excel and get rid of it from task manager processes also?