+ Reply to Thread
Results 1 to 8 of 8

VBA to delete connection with references

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    VBA to delete connection with references

    Hi Guys,

    i am trying to delete connection "Table1" in VBA.
    the problem is that i can delete even manually i am getting message:

    Screenshot_217.png

    my code is:
    Please Login or Register  to view this content.
    So my idea is to find all references through code and delete one by one in proper order.
    How can i do this?

    Best,
    Jacek
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: VBA to delete connection with references

    Are you trying to delete the query or the connection? Your picture is the former but your code appears to be trying to do the latter.
    Rory

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: VBA to delete connection with references

    Thank you Rory,

    connection i tried. If this is connection only...

    Best,
    Jacek

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: VBA to delete connection with references

    Look at the picture and the error message. You were on the Queries tab of the pane, not the Connections tab, and the message said you couldn't delete the query as it was in use. What are you actually trying to do (and why)?

  5. #5
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: VBA to delete connection with references

    Ok Rory,

    thank you. I do not have connections.
    So i have to delete workbook queries instead of it!

    Ok got it,
    thank you,
    Jacek

  6. #6
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: VBA to delete connection with references

    One more thing:

    when i am trying to remove specific query:
    Please Login or Register  to view this content.
    i am getting error here: pq.Delete
    Run time error: 9 - > object or variable not set.

    Why if within loop works like a charm?

    Best,
    Jacek

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: VBA to delete connection with references

    You didn't use Set and you used pg not pq in the previous line.

  8. #8
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: VBA to delete connection with references

    Thank you!

    Jacek

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Delete connection after importing csv file into worksheet.
    By A440 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2019, 09:49 AM
  2. Delete listobject with query table based on connection name
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-27-2019, 04:37 AM
  3. how delete references in VBA editor, tools
    By PaulLag in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2019, 12:54 PM
  4. Update, Insert & Delete SQL Statements Using Data Connection Wizard
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-07-2015, 05:03 AM
  5. UNwanted External Connection - Cannot Delete
    By tempmember in forum Excel General
    Replies: 2
    Last Post: 09-16-2015, 04:25 AM
  6. [SOLVED] Delete an External Connection
    By Joakim N in forum Excel General
    Replies: 2
    Last Post: 03-03-2014, 06:16 AM
  7. Replies: 0
    Last Post: 11-09-2005, 04:50 PM

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