I have a workbook that imports data from a .txt file. In the process, it auto creates a named range "ExternalData_1", then the next update is "ExternalData_2" and so on. Since data is imported 3x weekly, this could quickly escalate into a whole lot of unneeded named ranges. As such, I want to remove the named range as part of the update process.
I tried adding a simple line of code: ActiveWorkbook.Names("ExternalData_1").Delete - but this is giving a 1004 error. Strange considering I test recorded the manual deletion of the named range and that's exactly what recorded.
I tried a more complex solution and while this one runs, it also causes corruption in the file. The file works just fine during that session, but the next time it's opened, it will go into recovery mode, which loses virtually all of the conditional formatting for some reason. The code I tried is:
I suspect that the corruption is somehow related to the fact that Names contains other references that touch on ExternalData_1. I tested this by replacing the EDName.Delete with a counter. Even though there is only one ExternalData_1 listed in the name manager, this code will return a counter of 6. I'm just not sure how to find out what the other 5 instances of ExternalData_1 occurring are.
Any help would be greatly appreciated. As is, we have to manually go into the Name manager weekly and delete the auto created ExternalData references...
I tried adding a simple line of code: ActiveWorkbook.Names("ExternalData_1").Delete - but this is giving a 1004 error. Strange considering I test recorded the manual deletion of the named range and that's exactly what recorded.
I tried a more complex solution and while this one runs, it also causes corruption in the file. The file works just fine during that session, but the next time it's opened, it will go into recovery mode, which loses virtually all of the conditional formatting for some reason. The code I tried is:
VBA Code:
Sub DelExtDataNR()
Dim EDName As Name
For Each EDName In Names
If InStr(1, EDName.Name, "ExternalData_1") Then
EDName.Delete
End If
Next EDName
End Sub
I suspect that the corruption is somehow related to the fact that Names contains other references that touch on ExternalData_1. I tested this by replacing the EDName.Delete with a counter. Even though there is only one ExternalData_1 listed in the name manager, this code will return a counter of 6. I'm just not sure how to find out what the other 5 instances of ExternalData_1 occurring are.
Any help would be greatly appreciated. As is, we have to manually go into the Name manager weekly and delete the auto created ExternalData references...