Got any Excel Questions? Free Excel Help
Saving an Excel Workbook/File as a Cell Text
It's quite common for Excel users to want to save their Excel file as a name that resides in Worksheet cell. The code below here shows you how this can be done. Where A1 is on a Worksheet with a Code Name of Sheet 1 and it houses the name to use.
Sub SaveAsCell() Dim strName As String On Error GoTo InvalidName strName = Sheet1.Range("A1") ActiveWorkbook.SaveAs strName Exit Sub InvalidName: MsgBox "The text: " & strName & _ " is not a valid file name.", vbCritical, "Ozgrid.com" End Sub
To add the code, open the Visual Basic Editor via Tools>Macro>Visual Basic Editor (Alt+F11) then go to Insert>Module and paste in the code above. To run the macro, go to Tools>Macro>Macros (Alt+F8) select the macro name and click "Run".
See also:
Saving Excel Tips, Tricks and Code |
Select Case Statement in Excel VBA |
Send Emails From Excel |
Working With Shapes In Excel VBA |
See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.