Byref doesn't coincide

Byref doesn't coincide

dibujocad
Enthusiast Enthusiast
598 Views
2 Replies
Message 1 of 3

Byref doesn't coincide

dibujocad
Enthusiast
Enthusiast

Hi everybody, I'm using part of a macro which was posted in this forum.

However, when I try to call the procedure “ReplaceFileReference” an error "Byref argument type mismatch" occurs. I know it’s an error related to wrong type variable definition, but I’m not able to fix it, any suggestion?

 

Sub Replace_idw()

 

    Dim oidwDoc As DrawingDocument

    Set oidwDoc = ThisApplication.ActiveDocument

   

    Dim Filename, NewFilename As String

    Filename = "C:\Users\uss\Desktop\Example.iam"

    NewFilename = "C:\Users\uss\Desktop\Example2.iam"

    Call ReplaceFileReference(oidwDoc, Filename, NewFilename)

 

End Sub

 

Private Sub ReplaceFileReference(oDoc As Document, oRefToRemove As String, oRefToInclude As String)

 

    Dim oFD As FileDescriptor

    For Each oFD In oDoc.File.ReferencedFileDescriptors

        If oFD.FullFilename = oRefToRemove Then

             oFD.ReplaceReference (oRefToInclude)

        End If

    Next

   

End Sub

0 Likes
Accepted solutions (1)
599 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @dibujocad.  Is it possible that the Type 'Document' is not exclusive to only Inventor's API among all of the other References you may currently have turned on?  I'm not sure if that would be the error it would show if that were the case though.  You may simply need to include those designation within your private Sub's definition line.  I would specify 'ByRef' for the Document, and 'ByVal' for the two String variables.  Since DrawingDocument is basically derived from the Document object, I would not think this situation would cause any problems though, as far as Type difference.

Here is a link to one of my contribution posts about the same process, but in iLogic, instead of VBA.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

dibujocad
Enthusiast
Enthusiast

Thank you @WCrihfield. I added what you told me in the code and it works perfectly. 

0 Likes