Change source of 3rd party spreadsheet.

Change source of 3rd party spreadsheet.

herrwolf1
Enthusiast Enthusiast
800 Views
5 Replies
Message 1 of 6

Change source of 3rd party spreadsheet.

herrwolf1
Enthusiast
Enthusiast
Hello,
0 Likes
801 Views
5 Replies
Replies (5)
Message 2 of 6

herrwolf1
Enthusiast
Enthusiast
Anyways,
Tab apparently goes straight to "Post Message"

To my problem.
The following code worked fine before I installed SP1. Can anyone spread some light onto what a solution might be.

Sub ChangeSource()
Dim oDoc As Document
Dim oFile As File
Dim oFileDesc As FileDescriptor
Dim Temp As String

Set oDoc = ThisApplication.ActiveDocument
Set oFile = oDoc.File

For Each oFileDesc In oFile.ReferencedFileDescriptors
If oFileDesc.FullFileName = MasterForm.lblPath.Caption & "\" & MasterForm.lblSpreadsheet.Caption Then
Temp = MasterForm.lblPath.Caption & "\" & MasterForm.lblSpreadsheet.Caption
oFileDesc.ReplaceReference (Temp) ' The code breaks here
End If
Next
End Sub
0 Likes
Message 3 of 6

Anonymous
Not applicable

You are missing the 'Call' keyword in the
following line:

 

oFileDesc.ReplaceReference (Temp)

 

should be:

 

Call oFileDesc.ReplaceReference (Temp)

 

This is a VB syntax oddity that has been
addressed in VB.NET.

 

Sanjay-
0 Likes
Message 4 of 6

herrwolf1
Enthusiast
Enthusiast
Hello Sanjay,



I tried adding the Call keyword. It didn't work. Here is the error I get:



Run-time error '-2147467259 (80004005)':

Method 'ReplaceReference' of object ' _IRxFileDescriptor' failed



Perhaps I have other problems.
0 Likes
Message 5 of 6

Anonymous
Not applicable

Hmm, I tried again and it works for me. Are you on
Inventor 2009? Perhaps you have an incorrect filepath to your
spreadsheet?

 

Also, if you intend to change the source of the
spreadsheet linked via the Parameters dialog, there is another way:

 

Sub ChangeExcelSource()

 

    Dim oDoc As
PartDocument
    Set oDoc =
ThisApplication.ActiveDocument
   
    Dim
oDef As PartComponentDefinition
    Set oDef =
oDoc.ComponentDefinition
   
    Dim oTable
As ParameterTable
    Set oTable =
oDef.Parameters.ParameterTables(1)
   
   
oTable.FileName = "C:\temp\test_copy.xls"
   
End
Sub

 

Sanjay-

 
0 Likes
Message 6 of 6

snichols
Advocate
Advocate

Can this be done in an Inventor 2009 .dwg also? I have a linked spreadsheet that is the parts list and I would like to change the source via a macro. I am not very good at VBA so please be gentle.

Thanks,

0 Likes