Saving an excel file by using a macro

Amaarouf

New Member
Joined
Oct 10, 2002
Messages
8
Hi,

I'm new to VBA, but I'm trying to create a macro that will save an excel file as a cell name. The code that I have written so far is:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ThisFile = Range("V4").Value
ActiveWorkbook.SaveAs Filename:=ThisFile
ActiveWorkbook.SaveAs Filename:="W:SharedDummyMTC Tracking SheetMTC" & ThisFile
End Sub

The problem is when I place this code in 'ThisWorkbook' under BeforeSave I get the following error msg:

'Excel.exe has generated errors and will be closed by Windows. You will need to restart the program, an error log has been created'

does anyone know what I might be doing wrong?

Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
What is in cell V4?

Do you really want to save the workbook twice - once in the current directory and then in W:SharedDummyMTC Tracking SheetMTC?
 
Upvote 0
Hi,

In V4 is an equation

=Sheet15!A1

I guess I only really need to save it once in W:SharedDummyMTC Tracking SheetMTC

thanks
 
Upvote 0
Try this:
Public Sub SaveAsA1()
'Saves file as what is in cell "A1" to specified network location

Dim Location, ThisFile As String

Location = "\directorysubdirectory"
ThisFile = Range("A1")
ThisFile = Location + ThisFile
ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub

Chris;)
 
Upvote 0
I have this in a module in my personal.xls. It will save the file to whatever name you have in cell A1. It will save it to the current directory unless you have a full path in A1.

Public Sub SaveAsA1()
ThisFile = Range("A1").Value
If ThisFile = "" Then Exit Sub
ActiveWorkbook.SaveAs FileName:=ThisFile

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,548
Members
449,038
Latest member
Guest1337

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
Back
Top