Help - Search - Members - Calendar
Full Version: Vba Code For "save As"
BleepingComputer.com > Software > Programming
   
IrishLefty
I want to put a button marked "SAVE AS" on my spreadsheet, and when it's clicked have the macro read the contents of Cell A1, add .xls to it and incorporate it in the Save As function. In other words, I need to speed up the Save As process such that all I have to do is type the name in Cell A1 and click the SAVE AS Button to save the document. Any ideas? I'm using Excel 2007.

Thank you
adh_amit
Try this code:

Sub main()
fileI = ActiveSheet.Cells(1, 1).Value
FileN = fileI + ".xlsm"

ActiveWorkbook.SaveAs Filename:=FileN, FileFormat:=52

End Sub

Filefomat = 52 means file type is Open XML Workbook Macro Enabled. Excel2007 wont let you save the workbook in any other fomat since it contain a macro.

About the button part, I would suggest having a keyboard shortcut when you write this macro.e.g if Ctrl+T is your shortcut,
once you type Ctrl T, the current workbook will be saved to A1value.xlsm.

If you also want to close the file as soon as you save, add one more line to the code
activeworkbook.close savechanges:= true


Hope this helps.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.