Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA code for Excel File Save As

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default VBA code for Excel File Save As

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA code for Excel File Save As

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA code for Excel File Save As

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA code for Excel File Save As

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA code for Excel File Save As

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default VBA code for Excel File Save As

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code the Macro to save and close a file? Eric Excel Discussion (Misc queries) 7 June 10th 07 03:28 PM
FILE 'SAVE AS' IN VBA CODE Sally Excel Discussion (Misc queries) 3 June 28th 06 03:41 PM
Macro VBA code to name Save-As file Dolores Excel Worksheet Functions 7 December 28th 05 11:24 PM
Save Excel file - prompts to save - no Volitile functions used POWER CERTS Excel Worksheet Functions 2 November 1st 04 09:27 PM
prevent user from saving file to a folder but allow my code to save from behind. susie Excel Programming 3 July 25th 03 03:01 PM


All times are GMT +1. The time now is 02:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"