Results 1 to 4 of 4

Thread: visual basic to excel on xp but not win 98

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Location
    surat
    Posts
    4

    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.

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Do both machines have the same version of Excel on?
    What is your code you're using to create the Excel objects?

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Location
    surat
    Posts
    4
    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

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width