Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
AlexFielder
in reply to: AlexFielder

Strange...

 

I just modified the same ilogic code above to work in vba and lo, it works as expected.

 

Here's my original source modified to be vba-friendly:

 

Public Sub addolereferences()


Dim doc As Document
Set doc = ThisApplication.ActiveDocument

'Verify the current document has been saved.
If doc.FullFileName = "" Then
    MessageBox.Show ("This document must be saved first.")
    Exit Sub
End If

Dim selectedfile As String
'Set selectedfile = ""
Dim oFileDlg As Inventor.FileDialog
Set oFileDlg = Nothing
Call ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.filter = "Dwg files (*.dwg)|*.dwg|Excel files (*.xlsx)|*.xlsx|pdf files (*.pdf)|*.pdf|Inventor parts (*.ipt)|*.ipt"
oFileDlg.InitialDirectory = oOrigRefName
oFileDlg.CancelError = True
oFileDlg.MultiSelectEnabled = True
On Error Resume Next
Call oFileDlg.ShowOpen
If Err.Number <> 0 Then
Return
ElseIf oFileDlg.FileName <> "" Then
selectedfile = oFileDlg.FileName
End If

'MessageBox.Show("You selected: " & selectedfile , "iLogic")
Dim oleReference As ReferencedOLEFileDescriptor
If InStr(1, selectedfile, "|") > 0 Then
    'If selectedfile.Contains("|") Then ' we have multiple files selected.
    Dim file() As String
    file() = Split(selectedfile, "|")
        For Each s In file
            'MessageBox.Show("You selected: " & s , "iLogic")
            oleReference = doc.ReferencedOLEFileDescriptors.Add(s, kOLEDocumentLinkObject)
            oleReference.BrowserVisible = True
            oleReference.Visible = True
            oleReference.DisplayName = Mid$(s, InStrRev(s, "\") + 1)
        Next
    Else
        oleReference = doc.ReferencedOLEFileDescriptors.Add(selectedfile, kOLEDocumentLinkObject)
        oleReference.BrowserVisible = True
        oleReference.Visible = False
        oleReference.DisplayName = Mid$(selectedfile, InStrRev(selectedfile, "\") + 1)
    End If
End Sub

 

the one functional change (which makes no difference in iLogic!) is 

oleReference.Visible = True

 instead of the previous:

 

oleReference.Visible = False

 

Is this a bug or "as intended"? Smiley Embarassed