+ Reply to Thread
Results 1 to 4 of 4

End Querytable

  1. #1
    Registered User
    Join Date
    07-29-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    51

    End Querytable

    I have created a macro that will import external data from a USB drive using a querytable. The problem is that after the info is imported from the USB drive, then the "Safely Remove Hardware" option doesn't work for the USB drive. I am guessing the Excel is still using the USB drive, as once Excel is closed, then the "Safely Remove Hardware" option is viable again.

    What I need is to be able to automatically re-enable the "Safely Remove Hardware" feature without having to close Excel, or without having to close the worksheet. What I think I need is some way to end the querytable connection from the worksheet to the USB drive.

    I don't need to be able to constantly refresh the query. Once the query is performed the first time, and once the data I need in imported, then I am done with importing data.

    Is there such thing as using a "querytable.quit" in my VBA code?

    Thank you in advance!

  2. #2
    Registered User
    Join Date
    07-29-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    51

    Re: End Querytable

    ^bump^ Is it even possible to end the query connection without closing the spreadsheet?

  3. #3
    Registered User
    Join Date
    07-29-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    51

    Re: End Querytable

    Ok, I think that I know what needs to be done. I believe that I need to delete the query in VBA.

    I found some code that might help:

    Sheets("Sheet1").QueryTables.Item("MyTable").Delete

    or

    Sheets("Sheet1").QueryTables(1).Delete

    However, whenever I put this into my VBA code, I get an error '9'.

    I'm not exactly sure what this means, but I think that it could be because I am putting it in the wrong place.

    Here is a snippet of my code:

    Please Login or Register  to view this content.
    Any help is appreciated. Thanks!

  4. #4
    Registered User
    Join Date
    07-29-2010
    Location
    Indiana
    MS-Off Ver
    Excel 2003, 2010, 2013
    Posts
    51

    Re: End Querytable

    ^Bump^^Bump^

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1