CSV import connection not renaming?

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

CSV import connection not renaming?

Post by Rudi »

Hi,

Any idea why the connection does not rename based on the code?
At the end of the import, I want to break the connection (delete it) so there is no reference to the source CSV file. By default the connection name is based on the csv file name, but this can change by month, so how does one delete the connection if I cannot rename it to a static name?

TX
1B.jpg
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: CSV import connection not renaming?

Post by HansV »

You don't need to know the name of the connection. You can delete it at the end of the With ... End With block:

Code: Select all

        ...
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
        .Delete
    End With
End Sub
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: CSV import connection not renaming?

Post by HansV »

Oh, and by the way: the line

Code: Select all

        .Name = "SourceData"
does not set the name of the connection, but of the imported range.
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: CSV import connection not renaming?

Post by Rudi »

TX for both those details. Important to know and working now... :cheers:
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.