Message 1 of 9
Not applicable
10-13-2021
11:46 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I'm interesting if is possible to replace embeded excel file if is not linked?
On forum I was find one iLogic rule, which is work perfect, but with this rule I can replace only linked excel file.
Thank you a lot for any help.
With kind regards,
Jernej Puc
Sub Main()
Dim oAssyDoc As Inventor.AssemblyDocument = ThisDoc.Document
Dim OldExcelFile As String = InputBox("What was the full name of the old linked Excel file? (Includes file path)", "Old Linked Excel file", "")
Dim NewExcelFile As String = InputBox("What is the full name of the new linked Excel file? (Includes file path)", "New Linked Excel file", OldExcelFile)
'Handle Top level Doc
Call ReplaceRefFile(oAssyDoc, OldExcelFile, NewExcelFile)
'Iterate through sub level docs.
Dim oDoc As Inventor.Document = Nothing
For Each oDoc In oAssyDoc.AllReferencedDocuments
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Or oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
Call ReplaceRefFile(oDoc, OldExcelFile, NewExcelFile)
End If
Next
oAssyDoc.update2(True)
MsgBox("Done", MsgBoxStyle.Information, "Done")
End Sub
Sub ReplaceRefFile(oDoc As Document, OldExcelFile As String, NewExcelFile As String)
Dim oReferencedFile As Inventor.ReferencedOLEFileDescriptor = Nothing
If oDoc.ReferencedOLEFileDescriptors.Count > 0 Then
If oDoc.IsModifiable = True
For Each oReferencedFile In oDoc.ReferencedOLEFileDescriptors
If oReferencedFile.FullFileName = OldExcelFile Then
oReferencedFile.FileDescriptor.ReplaceReference(NewExcelFile)
oDoc.Update2(True)
End If
Next
Else
MsgBox(oDoc.FullFileName & vbLf & "is not modifiable. References NOT replaced")
End If
End If
End Sub
Solved! Go to Solution.