change the path of the filesaveas dialog box

change the path of the filesaveas dialog box

shastu
Advisor Advisor
734 Views
5 Replies
Message 1 of 6

change the path of the filesaveas dialog box

shastu
Advisor
Advisor

I am using the saveas dialog box from a vba macro using this code:

 

On Error Resume Next

Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
   
    ' Get the CommandManager object.
    Dim oCommandMgr As CommandManager
    Set oCommandMgr = ThisApplication.CommandManager


    ' Get control definition for the line command.
    Dim oControlDef As ControlDefinition
    Set oControlDef = oCommandMgr.ControlDefinitions.Item("AppFileSaveAsCmd")
    ' Execute the SaveAS command.

    
    Call oControlDef.Execute

 

If I have a particular path that I have extracted in my code, can I get it to go to that path when calling the oControlDef.Execute?  Like lets say instead of the current location of the file, I want the save as dialog box to open to the location of C:\Temp.

0 Likes
735 Views
5 Replies
Replies (5)
Message 2 of 6

Curtis_Waguespack
Consultant
Consultant

Hi shastu,

 

I don't think you can do so using the command manager method, but you can specify the initial directory using something like this example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

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

EESignature

0 Likes
Message 3 of 6

shastu
Advisor
Advisor

Thanks for the quick response.  It still doesn't go to the C:\Temp folder.  Also, with the actual SaveAs command the original file name of the original file is already in the field and then you can just modify it.  When I use your example it is completely blank.  Also, it seems as if this is just controlling the dialog box, but it isn't actually saving anything because when I type something in and hit the save button, my file is not saved.

0 Likes
Message 4 of 6

Curtis_Waguespack
Consultant
Consultant

Hi shastu,

 

 

oops sorry, I did a straight paste from the API examples and didn't look at it closely.

 

This example, is a save as that actually does a save as.

 

However, I still can't get the initial directory setting to work properly. Smiley Frustrated

 

I feel like I've seen a post on here about the initial directory setting and why/how it works/doesn't work, if I can find it I'll post back.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

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;*.idw)|*.iam;*.ipt;*.idw|All Files (*.*)|*.*"

    ' Define the default filter.
    oFileDlg.FilterIndex = 1

    ' Set the title for the dialog.
    oFileDlg.DialogTitle = "Custom Save As"
    
    ' Set the initial directory that will be displayed in the dialog.
    oFileDlg.InitialDirectory = "C:\Temp"
    
    oFileDlg.FileName = ThisApplication.ActiveDocument.FullDocumentName
    
    ' 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
        MyFile = oFileDlg.FileName
        Call ThisApplication.ActiveDocument.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
    End If
End Sub

EESignature

0 Likes
Message 5 of 6

shastu
Advisor
Advisor

The other thing about doing it this way is that you don't truly get all of the functionality of the SaveAs command.  For instance, when you use the actual SaveAs command, the Part Number in the Project and Status tabs also update.  With your method, they don't.  I should be able to figure out the code to change these two fields but what else may I be missing?

0 Likes
Message 6 of 6

shastu
Advisor
Advisor

Looks like the oFileDlg.Filename is what is determining the location given to the user.  So I will just have to modify my code and break that line out to a path + filename and then figure out how to change the other fields like the SaveAs command does.  Thanks for your help Curtis.