how do i write vb code that asks user for the save as filename?
thanks!
how do i write vb code that asks user for the save as filename?
thanks!
Hello,
if you want exactly the same as the save as-function in Excel, you have to create a userform in Vba and put a commondialog control on it(rigth click on the toolbox - additional controls - microsoft commondialog control "6.0").
Code behind a button:
[vba]'Initialize commondialog-box
frmFormulier.CommonDialog.DialogTitle = "Save as ..."
frmFormulier.CommonDialog.InitDir = ActiveWorkbook.Path 'start-path
frmFormulier.CommonDialog.Filter = "Excelfile|*.xls" 'Type of file
frmFormulier.CommonDialog.Filename = "" 'Standard file name
'Show type of commondialig-box open, save, ...
frmFormulier.CommonDialog.ShowSave
'Save workbook
Select Case frmFormulier.CommonDialog.Filename
Case Is <> ""
'There is a name filled in
ActiveWorkbook.SaveAs frmFormulier.CommonDialog.Filename
End Select[/vba]
I have uploaded a small example.
Gollem
Don’t have an account yet? Register yourself now and be a part of our community!