Replacing Referenced Files Using VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a project where I need to automate the creation of .ipt, .idw and .iam files based off of a set of template files. All was working extremely well until I had to handle an .iam file that had two references to the same .ipt file. If the new .iam file still links to the same .ipt file twice then everything works fine. If the new .iam file has to point to two different .ipt files I have a problem. The code I originally used was:
Assem.File.ReferencedFileDescriptors(Index).ReplaceReference(NewFilePath)
where Assem is defined as AssemblyDocument. Now, in order to just change a single reference I use:
Assem.ComponentDefinition.Occurrences(Index).Replace(NewFilePath, False) 'or True if all the references still need to be the same
The problem is that using the second method of replacement works, but it leaves a reference to the old .ipt file in the ReferencedFileDescriptors collection. I need to know how to get rid of that reference, or if there's a different way I can replace single or mulitple instances of the same reference with one function call. I hope I've explained this clearly enough.
Tom
