MPW
Well-known Member
- Joined
- Oct 7, 2009
- Messages
- 571
- Office Version
- 365
- Platform
- Windows
Hi,
I have successfully been loading multiple text files into Excel using
and then deleting the connection
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.
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.
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
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.
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.