Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I'm building a code where at some point I need to save the file to a new location with a specific file name, which is also specified by the code. I would like to be prompted for this but it only saves if I specify the path. This is the bit I have already written and can't go further: Dim NewName As String NewName = mRateName & " " & Validade & ".xls" If MsgBox("Save file as " & NewName & "?", vbYesNo, Save) = vbNo Then Exit Sub ActiveWorkbook.SaveAs FileName:=NewName Can anyone help me? Thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You can use GetSaveAsFilename
Sub Test() Dim fname As Variant Dim Wb As Workbook Set Wb = ActiveWorkbook fname = Application.GetSaveAsFilename("", _ fileFilter:="Excel Files (*.xls), *.xls") If fname < False Then Wb.SaveAs fname 'Wb.Close False Set Wb = Nothing Else Set Wb = Nothing End If End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "khlaudhya" wrote in message ... Hi, I'm building a code where at some point I need to save the file to a new location with a specific file name, which is also specified by the code. I would like to be prompted for this but it only saves if I specify the path. This is the bit I have already written and can't go further: Dim NewName As String NewName = mRateName & " " & Validade & ".xls" If MsgBox("Save file as " & NewName & "?", vbYesNo, Save) = vbNo Then Exit Sub ActiveWorkbook.SaveAs FileName:=NewName Can anyone help me? Thanks |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi khlaudhya,
If mRateName and Validade are strings, you need to enclose them with double quotes. Similarly, you need to enclose the title argument (Save) of the msgbox in quotes. You also need to provide an End If to close your If clause. Incorporating thesr changes your code works for me and becomes: Sub Test Dim NewName As String NewName = "mratename" & " " & "Validade" & ".xls" If MsgBox("Save file as " & NewName & "?", vbYesNo, "Save") = vbNo Then Exit Sub End If ActiveWorkbook.SaveAs Filename:=NewName End Sub The new file will be saved your default file location. If you wish to save to another folder, simply prefix NewName with the full folder path. --- Regards, Norman "khlaudhya" wrote in message ... Hi, I'm building a code where at some point I need to save the file to a new location with a specific file name, which is also specified by the code. I would like to be prompted for this but it only saves if I specify the path. This is the bit I have already written and can't go further: Dim NewName As String NewName = mRateName & " " & Validade & ".xls" If MsgBox("Save file as " & NewName & "?", vbYesNo, Save) = vbNo Then Exit Sub ActiveWorkbook.SaveAs FileName:=NewName Can anyone help me? Thanks |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Khlaudhya,
Reading Ron's reply, I realise that I failed to appreciate that you want the user to provide the path whilst the code designates the file name. --- Regards, Norman "khlaudhya" wrote in message ... Hi, I'm building a code where at some point I need to save the file to a new location with a specific file name, which is also specified by the code. I would like to be prompted for this but it only saves if I specify the path. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Ron,
thank you very much, this was really helpful. Regards, Khlaudhya "Ron de Bruin" wrote: You can use GetSaveAsFilename Sub Test() Dim fname As Variant Dim Wb As Workbook Set Wb = ActiveWorkbook fname = Application.GetSaveAsFilename("", _ fileFilter:="Excel Files (*.xls), *.xls") If fname < False Then Wb.SaveAs fname 'Wb.Close False Set Wb = Nothing Else Set Wb = Nothing End If End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "khlaudhya" wrote in message ... Hi, I'm building a code where at some point I need to save the file to a new location with a specific file name, which is also specified by the code. I would like to be prompted for this but it only saves if I specify the path. This is the bit I have already written and can't go further: Dim NewName As String NewName = mRateName & " " & Validade & ".xls" If MsgBox("Save file as " & NewName & "?", vbYesNo, Save) = vbNo Then Exit Sub ActiveWorkbook.SaveAs FileName:=NewName Can anyone help me? Thanks |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Norman,
thanks for trying to help but Ron really did answer what I was asking. Regards, Khlaudhya "Norman Jones" wrote: Hi Khlaudhya, Reading Ron's reply, I realise that I failed to appreciate that you want the user to provide the path whilst the code designates the file name. --- Regards, Norman "khlaudhya" wrote in message ... Hi, I'm building a code where at some point I need to save the file to a new location with a specific file name, which is also specified by the code. I would like to be prompted for this but it only saves if I specify the path. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ron your code works great. Is there a way to incorporate into the code that
allows me to pick up a textbox with the data entered in there to be part of the file name upon saving the workbook? "Ron de Bruin" wrote: You can use GetSaveAsFilename Sub Test() Dim fname As Variant Dim Wb As Workbook Set Wb = ActiveWorkbook fname = Application.GetSaveAsFilename("", _ fileFilter:="Excel Files (*.xls), *.xls") If fname < False Then Wb.SaveAs fname 'Wb.Close False Set Wb = Nothing Else Set Wb = Nothing End If End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "khlaudhya" wrote in message ... Hi, I'm building a code where at some point I need to save the file to a new location with a specific file name, which is also specified by the code. I would like to be prompted for this but it only saves if I specify the path. This is the bit I have already written and can't go further: Dim NewName As String NewName = mRateName & " " & Validade & ".xls" If MsgBox("Save file as " & NewName & "?", vbYesNo, Save) = vbNo Then Exit Sub ActiveWorkbook.SaveAs FileName:=NewName Can anyone help me? Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to code the Macro to save and close a file? | Excel Discussion (Misc queries) | |||
FILE 'SAVE AS' IN VBA CODE | Excel Discussion (Misc queries) | |||
Macro VBA code to name Save-As file | Excel Worksheet Functions | |||
Save Excel file - prompts to save - no Volitile functions used | Excel Worksheet Functions | |||
prevent user from saving file to a folder but allow my code to save from behind. | Excel Programming |