PDA

View Full Version : Solved: Suggest a file name



Djblois
12-11-2007, 01:30 PM
I have code that I use througout my add-in to bring up a save as dialog. However, I am trying to add it so it suggests a file name but I can't figure out how to do that part. Here is the code that I am using:

Sub SaveCode(Optional ByVal stgDirectory As String = "H:")

Dim wbFileName As String, stgSelectedDirectory As String, blnShowAlert As Boolean

On Error GoTo SaveNoDirectory
ChDrive "H:"
ChDir stgDirectory 'Change Directory to the users default directory
SaveNoDirectory:

'If the user hasn't set a Default Directory
wbFileName = Application.GetSaveAsFilename

On Error GoTo SaveBook
If wbFileName = "False" Then
blnShowAlert = GetSetting("Business Reporting Today", "General", "Alert-Save", True)
If blnShowAlert = True Then
frmErrorAlert.Show
If frmErrorAlert.cbDontShow Then
SaveSetting "Business Reporting Today", "General", "Alert-Save", False
Else
SaveSetting "Business Reporting Today", "General", "Alert-Save", True
End If
Unload frmErrorAlert
End If
errUpdateLogFile "SaveCode-NoSave"
Exit Sub
End If

SaveBook:

'Get the User specified directory
stgSelectedDirectory = Left(wbFileName, InStrRev(wbFileName, "\") - 1)

'Check if Directory the user is trying to save in is Read-Only - this part still
'Doesn't work
If GetAttr(stgSelectedDirectory) And vbReadOnly Then
MsgBox "Test"
End If

'If the user didn't type the file extension, this will add it
If Right(wbFileName, 5) = ".xlsx" Then
ActiveWorkbook.SaveAs wbFileName, FileFormat:=xlNormal
Else
ActiveWorkbook.SaveAs wbFileName & ".xlsx", FileFormat:=xlNormal
End If

End Sub

Bob Phillips
12-11-2007, 02:00 PM
GetSaveAsFilename has an Initial Filename property.

Djblois
12-11-2007, 02:03 PM
how come some code you hit a spacebar and the needed properties will show up but others you need to add a ( for them to show up? Also, how would I know the difference? Maybe, so I can't make this big mistake again?

Bob Phillips
12-11-2007, 02:10 PM
Don't really know mate. Intellisense works fine for me, I type

mpFilename = Application.GetSaveAsFilename(

and all the properties popup, with the next in line being bold. Of course I do have the AUto List Options checked in Tools>Options...>Editor.