Hello to everyone,
I wrote a code, which allows me to automatically import the Text (.txt) files (that are located in the same folder) on different worksheets (according to a certain criteria).
But I have a problem with the duplication of data: I would like to import one text file only once. In this respect, I decided to check all the existing workbook [data] connections and if it would contain the file name, that I am going to import, exit the code.
I am new to VBA so I am not quite sure how to do this. It should be something like that:
This code works fine when there is only one workbook connection. But as far as there are a lot of connections (and the code would execute every time it would not find a coincidence between the Connection Name and and a File Name), I would like to check all the connections and compare them to the File that is being imported and in case of a single coincidence, exit the Sub.
Thank you very much in advance for your kind support.
I wrote a code, which allows me to automatically import the Text (.txt) files (that are located in the same folder) on different worksheets (according to a certain criteria).
But I have a problem with the duplication of data: I would like to import one text file only once. In this respect, I decided to check all the existing workbook [data] connections and if it would contain the file name, that I am going to import, exit the code.
I am new to VBA so I am not quite sure how to do this. It should be something like that:
Code:
Dim CON As WorkbookConnection
For Each CON In ActiveWorkbook.Connections
If CON.Name = 'Name of the file that I am going to import Then
Exit Sub
Else
' Main Code
End If
Next Conn
End Sub
This code works fine when there is only one workbook connection. But as far as there are a lot of connections (and the code would execute every time it would not find a coincidence between the Connection Name and and a File Name), I would like to check all the connections and compare them to the File that is being imported and in case of a single coincidence, exit the Sub.
Thank you very much in advance for your kind support.