I've been using the following code to specify a folder path in Excel:
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Show
I would Export pdf files (via VBA code) to that path. This code worked flawlessly when I had Excel 2007 running on Windows XP. I recently upgraded my operating system and office version, now I have Excel 2010 running on Windows 7. The code no longer works as it did, the problem is that the path keeps on moving up by one level every time I run the code.
For example, suppose I select the following Path:
\users\AK\Desktop\Projects\ProjectM
The actual pdfs are saved in \users\AK\Desktop\Projects\
If I select: \users\AK\Desktop\Projects\
the pdfs are saved in \users\AK\Desktop\
If I keep running the code, it will always jump up by one level, so lets say I run it 3 times sequentially (without selecting my path each time), my pdf files would be stored at: \users\AK\
I don't know if its an Excel 2010 issue or Windows 7 issue. Has anyone encountered that?
Edit: Full code included:
Private Sub CODERUN()
' Define values
FN_A = Cells(2, 2).Value
' Print PDF version
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Show
' Print PDF version
Sheets("Part A").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:=FN_A & "_A", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub
GetSaveAsFilenameto save files in any format although i haven't tried it with PDF since above is a little bit more complicated.