|
-
Jan 8th, 2004, 11:59 AM
#1
Thread Starter
New Member
visual basic to excel on xp but not win 98
i have developed one application in visual basic to save datagrid data to excel 2000.
when i run an application on windows 98 to save my data to excel -2000 , i am getting "Automation Error". (Excel.application is not getting initialiezed, reason is not known)
But when i run it on Windows XP machine with excel 2000, its working okay.
Pls help me to solve this problem out.
-
Jan 9th, 2004, 03:55 AM
#2
Do both machines have the same version of Excel on?
What is your code you're using to create the Excel objects?
-
Jan 10th, 2004, 10:10 AM
#3
Thread Starter
New Member
both machine use same excel 2000. below are my code for that
Dim strsavefile As String
On Error GoTo saverr
Set oexcel = Excel.Application
Set obook = oexcel.Workbooks.Add
Set osheet = obook.Worksheets(1)
With dlgsave ' CommonDialog object
.Filter = "excel (*.xls) | *.xls"
.DefaultExt = "xls"
.CancelError = True
.ShowSave
strsavefile = .FileName
If strsavefile = "" Then Exit Sub
'Qry = "select dt,time,type,tag,text,status,area from tbldcs order by id desc"
'ManipulateAdo adorsalarmxls, Qry
If AdoRsAlarm.EOF = True Or AdoRsAlarm.BOF = True Then Exit Sub
For rcnt1 = 1 To dg1.ApproxCount
For clcnt = 1 To dg1.Columns.Count - 1
clval = dg1.Columns.Item(clcnt)
osheet.Cells(rcnt1, clcnt).Value = clval
If AdoRsAlarm.EOF Then Exit Sub
Next
AdoRsAlarm.MoveNext
Next
obook.SaveAs (strsavefile)
MsgBox " File Saved"
End With
Set osheet = Nothing
Set obook = Nothing
Set oexcel = Nothing
Exit Sub
saverr:
MsgBox Err.Description
-
Jan 13th, 2004, 08:39 AM
#4
1) Set the excel object as new:
change oexcel = Excel.Application to :
'Dim oexcel as Excel.Application - if not done already
Set oexcel = new Excel.Application
2) Lookup the copyfromrecordset method for the middle bit
- it'll save you coding
3) Call the .close methods for the obook and workbook objects before setting them to nothing.
It sounds as though number 1 should sort this problem, I'm not sure how you are using the dim statement with these variables, but you certainly need the new keyword for this to work effectively.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|