Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBA FileDialog object - problem with InitialDirectory

24 REPLIES 24
Reply
Message 1 of 25
liborb
2256 Views, 24 Replies

VBA FileDialog object - problem with InitialDirectory

I need (in VBA makro) save file to given folder.
I want to do it with FileDialog object but I can't set folder in dialog windows with InitialDirectory method.
There is always last used folder in dialog window.
Does anybody know why InitialDirectory doesn't work?

{code}
Call ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = "C:\temp"
oFileDlg.ShowSave
{code}
24 REPLIES 24
Message 21 of 25
ccoomes
in reply to: xiaodong_liang

After reading this thread, I tried one of the first suggestions about using the full path & file name for the .FileName and it worked.

 

With some further tweaking, I have been able to get this to change the file extension as required to .xlsx

 

I have tried it on a couple of parts.  Further testing will confirm it works (Hopefully)

 

This is the code I have that works (I have only shown the Bits that I have changed as there are lots of non relvant bits in between):

 

Dim strFileName As String
Dim strFileFullPath As String

Dim oDocType As Document
Set oDocType = ThisApplication.ActiveDocument

strFileFullPath = oDocType.FullDocumentName
strFileName = Left(strFileFullPath, Len(strFileFullPath) - 4)

oFileDlg.InitialDirectory = strFileFullPath
oFileDlg.FileName = strFileName

 

We are using Inventor 2014, with Service Pack 1 installed.

 

Hope this helps.

Message 22 of 25
akosi
in reply to: philippe.leefsma

the .InitialDirectory doesnt work for me too...Smiley FrustratedSmiley Mad

 

im using 2013...

 

 

Message 23 of 25
ccoomes
in reply to: akosi

Not sure if this will work in 2013, but to get the .InitialDirectory & the .FileName to work correclt, Inventor 2014 needs to look for the FULL Path & File name (Including the Full Path) for both.

 

I originally had it set for the .InitialDirectory at the Full Path, and the .FileName at JUST the File Name and it did not work.

 

I then tried the suggestion by liborb that the File Name MUST also show the full Path and it then worked for me.

 

We are using this code to export some work points and then save the file as an Excel File (.xslx).  I have tweaked the code slightly to remove the File Extension & the "." so the correct file extension can be added when the Save Dialog Box appears.  Please note that the code we use saves the excel file with the file name as the Part Number.xlsx in the Same directory as the Part.

 

I have also changed the code for the strFileName String so that it takes into account should the file extension for Inventor files increase in length.

 

Attached is a simple macro that we use to show the File Name & Path required for both the .InitialDirectory & .Filename Values so we can save our excel files in the same directory as the part.

 

Hope this helps.

Message 24 of 25
BrandonBG
in reply to: ccoomes

Problem still exists in 2016, however, I figured it out for my purposes. Not sure if this qualifies as a workaround, or if this is really the way the FileDialog object is supposed to work.

 

 

oFileDialog.InitialDirectory = ThisDoc.Path()
oFileDialog.FileName = ThisDoc.Path() &"\" & oNewFileName

oNewFileName does have a file extension. Dropping the backslash in between was the trick to getting the directory name to disappear and not pop up as part of the filename.

 

Brandon

Message 25 of 25
adam.nagy
in reply to: BrandonBG

Hi Brandon,

 

"Dropping the backslash in between was the trick"

Yes, making sure that the path string is correct and it contains the folder separators (usually backslash) at the right places is definitely needed.

 

Also, if you check the help file for FileDialog.FileName, it says:

"Property that gets and sets the full filename of the selected file." - which means path + filename, and that is what Inventor provides as well when the file has been selected and the user clicked "Save".

 

Cheers,

 

 

 

 



Adam Nagy
Autodesk Platform Services

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report