ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel Basic (https://www.excelbanter.com/excel-programming/285727-excel-basic.html)

Ganesan Thirumavalavan

Excel Basic
 
Dear Experts,

I have problem in the excel visual basic when I €˜Add workbooks it will show error €˜-2147023067 with description €˜Automation Error. This error occurred in few computers with windows 98 OS only. Part of my source code for excel basic here. What could be the problem? Please kindly guide me how to rectify the error.

Dim ExcelWorkbook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet
Set ObjExcel = GetObject("Excel.Application")
If ObjExcel Is Nothing Then
Set ObjExcel = CreateObject("Excel.Application")
End If
If ObjExcel Is Nothing Then
MsgBox "You must have Microsoft Excel 97 or 2000 loaded on this machine to use this sample", vbOKOnly + vbCritical, "Error"
Exit Function
End If

Set ExcelWorkbook = ObjExcel.Workbooks.Add 'error occured here

Set ExcelSheet = ExcelWorkbook.Worksheets(1)
ObjExcel.Visible = True
ExcelSheet.Visible = xlSheetVisible
ExcelSheet.Cells.Font.Name = "Arial"
ExcelSheet.Cells(1 + j).ColumnWidth = 3 'Line Number
ExcelSheet.Cells(2 + j).ColumnWidth = 7 'Model Number

I would appreciate if I get the guidance .
Thanks and Regards with
Ganesan Thirumavalavan.


Jim Cone

Excel Basic
 
Ganesan,

Declare the application variable...
Dim ObjExcel as Excel.Application
Insert the missing comma...
Set ObjExcel = GetObject(, "Excel.Application")

Regards,

Jim Cone
San Francisco, CA
'*******************
"Ganesan Thirumavalavan" wrote in message ...
Dear Experts,
I have problem in the excel visual basic when I €˜Add workbooks it will show error €˜-2147023067 with description €˜Automation Error. This error occurred in few
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet
Set ObjExcel = GetObject("Excel.Application")
If ObjExcel Is Nothing Then
Set ObjExcel = CreateObject("Excel.Application")
End If
If ObjExcel Is Nothing Then
MsgBox "You must have Microsoft Excel 97 or 2000 loaded on this machine to use this sample", vbOKOnly + vbCritical, "Error"
Exit Function
End If
Set ExcelWorkbook = ObjExcel.Workbooks.Add 'error occured here
Set ExcelSheet = ExcelWorkbook.Worksheets(1)
ObjExcel.Visible = True
ExcelSheet.Visible = xlSheetVisible
ExcelSheet.Cells.Font.Name = "Arial"
ExcelSheet.Cells(1 + j).ColumnWidth = 3 'Line Number
ExcelSheet.Cells(2 + j).ColumnWidth = 7 'Model Number
I would appreciate if I get the guidance .
Thanks and Regards with
Ganesan Thirumavalavan.



Patrick Molloy[_4_]

Excel Basic
 
(1) you are missing one important issue...IF excel isn't installed then the
two DIM's that you have will fail since the Excel Object Library will not be
installed.
(2) The Workbooks.Add method syntax is incorrect...see Help


--
Patrick Molloy
Microsoft Excel MVP
----------------------------------
"Ganesan Thirumavalavan" wrote in
message ...
Dear Experts,

I have problem in the excel visual basic when I 'Add' workbooks it will

show error '-2147023067' with description 'Automation Error'. This error
occurred in few computers with windows 98 OS only. Part of my source code
for excel basic here. What could be the problem? Please kindly guide me how
to rectify the error.

Dim ExcelWorkbook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet
Set ObjExcel = GetObject("Excel.Application")
If ObjExcel Is Nothing Then
Set ObjExcel = CreateObject("Excel.Application")
End If
If ObjExcel Is Nothing Then
MsgBox "You must have Microsoft Excel 97 or 2000 loaded on this

machine to use this sample", vbOKOnly + vbCritical, "Error"
Exit Function
End If

Set ExcelWorkbook = ObjExcel.Workbooks.Add 'error occured here

Set ExcelSheet = ExcelWorkbook.Worksheets(1)
ObjExcel.Visible = True
ExcelSheet.Visible = xlSheetVisible
ExcelSheet.Cells.Font.Name = "Arial"
ExcelSheet.Cells(1 + j).ColumnWidth = 3 'Line Number
ExcelSheet.Cells(2 + j).ColumnWidth = 7 'Model Number

I would appreciate if I get the guidance .
Thanks and Regards with
Ganesan Thirumavalavan.





All times are GMT +1. The time now is 08:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com