#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Tamarac, FL
    Posts
    2
    Rep Power
    0

    How do I close an Excel Workbook instance to prevent sharing violation?


    Here's an excerpt of my code:

    Dim xlApp As Excel.Application ' new instantiation of Excel
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet

    '-- Open Excel and Select CheckBook Worksheet
    xlApp.Workbooks.Open excelFile
    xlApp.ActiveWorkbook.Worksheets
    (txtActiveWorkSheet.Text).Select

    '-- Code in here to Update Excel Workbook


    xlApp.ActiveWorkbook.Save
    xlApp.ActiveWorkbook.Close
    xlApp.Workbooks.Close

    Set xlSheet = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Ireland
    Posts
    16
    Rep Power
    0
    Have you tried

    xlBook.close

    or
    '*** Close and save the workbook ***
    xlBook.Close(vbYes)
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Tamarac, FL
    Posts
    2
    Rep Power
    0
    I thought I had tried that, but I'm not sure anymore. I will give it a try. Thank you krinpit

IMN logo majestic logo threadwatch logo seochat tools logo