File open

File open

Anonymous
Not applicable
275 Views
3 Replies
Message 1 of 4

File open

Anonymous
Not applicable
The following is presented as an example in programming help. How do you actually get the file selected in the dialog to open instead of getting a message. My limited experience tells me that I'm missing something very obvious or else very complicated

Public Sub TestFileDialog()
' Create a new FileDialog object.
Dim oFileDlg As FileDialog
Call ThisApplication.CreateFileDialog(oFileDlg)

' Define the filter to select part and assembly files or any file.
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"

' Define the part and assembly files filter to be the default filter.
oFileDlg.FilterIndex = 1

' Set the title for the dialog.
oFileDlg.DialogTitle = "Open File Test"

' Set the initial directory that will be displayed in the dialog.
oFileDlg.InitialDirectory = "C:\Temp"

' Set the flag so an error will be raised if the user clicks the Cancel button.
oFileDlg.CancelError = True

' Show the open dialog. The same procedure is also used for the Save dialog.
' The commented code can be used for the Save dialog.
On Error Resume Next
oFileDlg.ShowOpen
' oFileDlg.ShowSave

' If an error was raised, the user clicked cancel, otherwise display the filename.
If Err Then
MsgBox "User cancelled out of dialog"
ElseIf oFileDlg.FileName <> "" Then
MsgBox "File " & oFileDlg.FileName & " was selected."
End If
End Sub
0 Likes
276 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
I've edited the code below to open the file instead of displaying the
message box.

Sanjay-

wrote in message news:5521305@discussion.autodesk.com...
The following is presented as an example in programming help. How do you
actually get the file selected in the dialog to open instead of getting a
message. My limited experience tells me that I'm missing something very
obvious or else very complicated

Public Sub TestFileDialog()
' Create a new FileDialog object.
Dim oFileDlg As FileDialog
Call ThisApplication.CreateFileDialog(oFileDlg)

' Define the filter to select part and assembly files or any file.
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files
(*.*)|*.*"

' Define the part and assembly files filter to be the default filter.
oFileDlg.FilterIndex = 1

' Set the title for the dialog.
oFileDlg.DialogTitle = "Open File Test"

' Set the initial directory that will be displayed in the dialog.
oFileDlg.InitialDirectory = "C:\Temp"

' Set the flag so an error will be raised if the user clicks the Cancel
button.
oFileDlg.CancelError = True

' Show the open dialog. The same procedure is also used for the Save
dialog.
' The commented code can be used for the Save dialog.
On Error Resume Next
oFileDlg.ShowOpen
' oFileDlg.ShowSave

' If an error was raised, the user clicked cancel, otherwise display the
filename.
If Err Then
MsgBox "User cancelled out of dialog"
ElseIf oFileDlg.FileName <> "" Then
'MsgBox "File " & oFileDlg.FileName & " was selected."

Dim oDoc As Document
Set oDoc = ThisApplication.Documents.Open(oFileDlg.FileName)

End If
End Sub
0 Likes
Message 3 of 4

Anonymous
Not applicable
As I thought, simple. I added True to assure visibility. Why was this not needed?
Set oDoc = ThisApplication.Documents.Open(oFileDlg.FileName, True)
0 Likes
Message 4 of 4

Anonymous
Not applicable
The OpenVisible argument defaults to True. So if not specified, a value of
True is assumed.

Sanjay-

wrote in message news:5521594@discussion.autodesk.com...
As I thought, simple. I added True to assure visibility. Why was this not
needed?
Set oDoc = ThisApplication.Documents.Open(oFileDlg.FileName, True)
0 Likes