Get a specific cell value/text inserted in a macro

G

Guest

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top