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.
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.
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
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,