FileDialog not save

FileDialog not save

Anonymous
Not applicable
490 Views
3 Replies
Message 1 of 4

FileDialog not save

Anonymous
Not applicable

Hi all,   I am having a problem with File Dialog code below.

When I open new part and need to save.

I then click save button on the File Dialog but not happen.

Can anybody help me?

Many thanks in advance!

 

P.S My English isn’t that good.

 

File Dialog API Sample

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 = "Save 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
491 Views
3 Replies
Replies (3)
Message 2 of 4

Owner2229
Advisor
Advisor

Hi, the "FileSave Dialog" doesn't actually save anything. It's just asking the user for file location. So in order to save the file, you have to do it yourself.

I guess it's VBA, right?

 

 

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 = "Save 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.
    'oFileDlg.ShowOpen
    oFileDlg.ShowSave

    If oFileDlg.FileName = vbNullString Then Exit Sub
MsgBox "File " & oFileDlg.FileName & " was selected."
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
oDoc.SaveAs(oFileDlg.FileName, True) End Sub

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi Owner2229

thanks a lot, i try to do both method oDoc.SaveAs and oDoc.Save. but not requirement.

please help me again. 

My requirement when I save part 

1. Set the initial directory by myself (same oFileDlg.InitialDirectory)

2. after saved, the part active on window ( same original inventor's save button ) that oDoc.SaveAs can not.

 

 

 

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

now I can do it.

I changed code below  a little at highlight.

It has property same native Inventor's save button.

 

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 = "Save 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.
    'oFileDlg.ShowOpen
    oFileDlg.ShowSave

    If oFileDlg.FileName = vbNullString Then Exit Sub
MsgBox "File " & oFileDlg.FileName & " was selected."
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
oDoc.SaveAs(oFileDlg.FileName, false) End Sub

 

 

0 Likes