![]() |
Get a specific cell value/text inserted in a macro
I am a new programmer in VBA and have many questions. This one first:
I want to make a macro, which saves a workarea as the value in a specific cell. ex. A1 contains the value 25, then I want the macro to save the workarea as 25.xls, without asking for the filename. I hope the question is understandable. |
Get a specific cell value/text inserted in a macro
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim s as String s = Thisworkbook.Path If right(s,1) < "\" then s = s & "\" End if On Error goto ErrHandler Application.DisplayAlerts = False Application.enableEvents = False thisworkbook.Saveas s & Thisworkbook _ .Worksheets("Data").Range("A1").Value & _ ".xls" ErrHandler: Cancel = True if err.Number < 0 then msgbox "Problems saving workbook" End if Application.EnableEvents = True Application.DisplayAlerts = True End Sub go into the VBE and select your project in the project explorer. On the ThisWorkbook Entry, right click and select view code. In the dropdowns at the top of the resulting module, select workbook from the left and beforesave from the right. Put in code like the above. -- Regards, Tom Ogilvy "ST" wrote: I am a new programmer in VBA and have many questions. This one first: I want to make a macro, which saves a workarea as the value in a specific cell. ex. A1 contains the value 25, then I want the macro to save the workarea as 25.xls, without asking for the filename. I hope the question is understandable. |
All times are GMT +1. The time now is 02:47 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com