saving

david hasslehof

New Member
Joined
Aug 17, 2006
Messages
28
I am trying to create a button which will let me print and save a file, I can do the printing bit but cannot save it, I want to save it under the name of cell f3 and c3. Is there any way this can be done???
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

this is the basic code
Code:
ThisWorkBook.SaveAs "fullname"
fullname will contain 3 parts
path
name
extension

parth could be the thisworkbook path
name will be in the cell
extension probably ".xls"


Code:
Sub Mysaveas()
Dim fName As String
Dim fPath As String

fPath = ThisWorkbook.Path
fName = Sheets(1).Range("C3")

ThisWorkbook.SaveAs fPath & Application.PathSeparator & fName & ".xls"

End Sub
hoping you will be able to use these "concatenation-tricks" in other circumstances

kind regards,
Erik
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
start the Visual Basic Editor (via Menu Tools, Macro or press ALT+F11).
On the Insert menu in the VBE, click Module. (if necessary)
In the module (the white area at the right), paste your code

to run the code
click anywhere in the code and hit function key F5
or
via Excel menu: Tools / Macro / Macros (or hit Alt+F8)


assign shortcutkey
menu Tools/Macro/Macros
select your macro
click options
choose a character as shortcut: example T
to run the macro press Ctrl+Shift+T
 

david hasslehof

New Member
Joined
Aug 17, 2006
Messages
28

ADVERTISEMENT

how do i set the path name is it something like h:/>dave>excel etc.?
 

david hasslehof

New Member
Joined
Aug 17, 2006
Messages
28
Sub Mysaveas()
Dim fName As String
Dim fPath As String

fPath = W:\RPD\DBrady\Excel\Special Deals\2006 Deals\quarter 3\September quotes

fName = Sheets(1).Range("f6")

ThisWorkbook.SaveAs fPath & Application.PathSeparator & fName & ".xls"

End Sub

I have put that in but it comes up as an error??
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
you are very close

when recording you get something like
Code:
ActiveWorkbook.SaveAs Filename:="C:\WINDOWS\Desktop\anyfile.xls"
you need to keep the quotes !
"C:\WINDOWS\Desktop"
 

Forum statistics

Threads
1,137,330
Messages
5,680,861
Members
419,937
Latest member
Talic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top