Avoiding Data Duplication using the Workbook Data Connections

Varlock

New Member
Joined
Aug 23, 2012
Messages
8
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:


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.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Something like this:
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


    Next Conn
    ' main code here
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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