Unable to delete Connection (Names do not match)

MPW

Well-known Member
Joined
Oct 7, 2009
Messages
571
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have successfully been loading multiple text files into Excel using
VBA Code:
                    firstfile = "TEXT;" & oFile
                    nmed = oFile.Name
                    With ActiveSheet.QueryTables.Add(Connection:=(firstfile), Destination:=Range("$A$1"))
                        .Name = nmed
                        ' all the other properties (.FieldNames, .RowNumbers, etc.)
                    End With
and then deleting the connection
VBA Code:
connctname = Left(nmed, Len(nmed) - 4) 'shaves off the extension of the file name
ActiveWorkbook.Connections(connctname).Delete

As stated, this was successful used in a prior workbook but in a new project it ceased to delete the connections.
Stepping through the code I see "connctname" = "01GENShh" which also matches the name in Queries & Connections, but it does not match the properties.
Capture.PNG


Capture.PNG


I have tried to delete all connections, but in break mode the connection does not exist in the code even though I can see it from the workbook view.
I tried to use the name in the properties to delete the connection with no success.
I also tried to delete the connection in the Queries & Connections window, but it was disabled. (until I close and reopen) the workbook.


I would like to continue using this method because it works well with foreign texts.
Problem is it bogs down the speed to a crawl as I could have as many as 39 books of text per project.

Question: Why are the names different and how can I import the text and then auto delete the connection?

Any idea are welcome. Thank you for your patience and help.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I found a separate problem with my code (perpetual loop). Straightened that out and all is right with the world again.
I want to close this ticket as solved (even though it did not need a solution). However if it should be deleted please let me know.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,603
Messages
6,179,854
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top