Results 1 to 3 of 3

Thread: Opening and closing excel in VB6

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    2

    Opening and closing excel in VB6

    I am trying to write a program which will open and close a spreadsheet. I am using the following code to do open the spreadsheet:

    Code:
    Dim xlapp As excel.Application
    Dim xlstudentbook As excel.Workbook
    Set xlapp = New excel.Application
    Set xlstudentbook = xlapp.Workbooks.Open(App.Path & "\Students.xls")
    To close the spreadsheet I am using this code:

    Code:
    Application.DisplayAlerts = False
    xlstudentbook.Saved = True
    xlstudentbook.Save
    xlstudentbook.Close
    Set xlstudentbook = Nothing
    Set xlapp = Nothing
    This all appears to work the first time the program closes the spreadsheet, however when the program closes it for the second time I still get a overwrite prompt.

    How can I avoid this prompt and just save the spreadsheet with no questions asked?

    Thanks in advance.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Opening and closing excel in VB6

    Welcome to VBForums

    The way you open it is fine, but the way you close it is not quite right.. see the Excel Tutorial link in my signature for examples of the correct methods (in post #5).

    If you still have problems after that, tell us the problem and show us your code (including the parts you didn't show before, as they can cause problems - even if they don't seem relevant).

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    2

    Re: Opening and closing excel in VB6

    Perfect, thanks very much.

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