ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SaveAs command doesn't save extension (https://www.excelbanter.com/excel-programming/387038-saveas-command-doesnt-save-extension.html)

stewart

SaveAs command doesn't save extension
 
I am trying to pull a SaveAs dialog box from a VB command that will
prompt the user to save their work. The problem is when the user
types in the filename it does not save as an excel file. The user
would have to type the extension themselves and that is not feasible
for this application. Below is the code I got from VB Help. Is there
another way?


sub savenew()
Set NewBook = Workbooks.Add
Do
fName = Application.GetSaveAsFilename
Loop Until fName < False
NewBook.SaveAs Filename:=fName
end sub


Norman Jones

SaveAs command doesn't save extension
 
Hi Stewart,

Try:

NewBook.SaveAs Filename:=fName & "xls", _
FileFormat:=xlWorkbookNormal

---
Regards,
Norman



"stewart" wrote in message
oups.com...
I am trying to pull a SaveAs dialog box from a VB command that will
prompt the user to save their work. The problem is when the user
types in the filename it does not save as an excel file. The user
would have to type the extension themselves and that is not feasible
for this application. Below is the code I got from VB Help. Is there
another way?


sub savenew()
Set NewBook = Workbooks.Add
Do
fName = Application.GetSaveAsFilename
Loop Until fName < False
NewBook.SaveAs Filename:=fName
end sub




Norman Jones

SaveAs command doesn't save extension
 
Hi Stewart,

Better would be:

'=============
Sub Savenew()
Dim NewBook As Workbook
Dim fName As Variant

Set NewBook = Workbooks.Add
Do
fName = Application.GetSaveAsFilename _
(fileFilter:="Excel Files (*.xls), *.xls")

Loop Until fName < False
NewBook.SaveAs Filename:=fName, _
FileFormat:=xlWorkbookNormal
End Sub
'<<=============


---
Regards,
Norman



Mike Fogleman

SaveAs command doesn't save extension
 
Try this:

Sub savenew()
Dim NewBook As Workbook
Dim fname As String
Set NewBook = Workbooks.Add
Do
fname = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls")

Loop Until fname < ""
NewBook.SaveAs Filename:=fname
End Sub


Mike F
"stewart" wrote in message
oups.com...
I am trying to pull a SaveAs dialog box from a VB command that will
prompt the user to save their work. The problem is when the user
types in the filename it does not save as an excel file. The user
would have to type the extension themselves and that is not feasible
for this application. Below is the code I got from VB Help. Is there
another way?


sub savenew()
Set NewBook = Workbooks.Add
Do
fName = Application.GetSaveAsFilename
Loop Until fName < False
NewBook.SaveAs Filename:=fName
end sub




stewart

SaveAs command doesn't save extension
 
Thank you for all your help. I used Normans suggestion and it did the
trick.

On Apr 8, 9:35 am, "Norman Jones"
wrote:
Hi Stewart,

Better would be:

'=============
Sub Savenew()
Dim NewBook As Workbook
Dim fName As Variant

Set NewBook = Workbooks.Add
Do
fName = Application.GetSaveAsFilename _
(fileFilter:="Excel Files (*.xls), *.xls")

Loop Until fName < False
NewBook.SaveAs Filename:=fName, _
FileFormat:=xlWorkbookNormal
End Sub
'<<=============

---
Regards,
Norman





All times are GMT +1. The time now is 12:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com