run 2 macro's in sequence

22868

New Member
Joined
Apr 4, 2002
Messages
13
Hi all,

Still a novice at VBA....................... Pffff hard work.

Can anybody tell me whats wrong with the following code:

Private Sub Workbook_open()

Dim TheNumber As Range

Set TheNumber = Sheets("sheet 1").Range("q3")

TheNumber.Value = TheNumber.Value + 1
[q4] = Date

End Sub

Private Sub Worksheet_open()

Sub ReNameFile()

ActiveWorkbook.SaveAs FileName:=Range("AA2").Value

End Sub


First bit works great. I am able to generate a sequential number on a sheet and add the date. Then I would like the sheet to change name (e.g. book1.xls) to the name which is in cell AA2. This only works when I manually execute the macro and I would like this to execute automaticly.

Any suggestions out there for this rookie?

Thanks,

Pete
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hello Pete, you can only have one Open event, no duplicates are allowed. This goes the same for every module in a workbook (except Standard & Class modules). Just combine the two ..

Code:
Private Sub Workbook_open()

Dim TheNumber As Range

Set TheNumber = Sheets("sheet 1").Range("q3")

TheNumber.Value = TheNumber.Value + 1
Sheets("sheet 1").Range("q4") = Date

Me.SaveAs FileName:=Range("AA2").Value

End Sub

Assumes you have a valid filename in AA2 AND it is on the current sheet which the workbook opens up to - otherwise you'll need to expressly code which sheet it's on.
 
Upvote 0
22868 said:
Private Sub Worksheet_open()
There is no such event as a Worksheet_Open event.
Zack may well have answered your question, however, if you're actually trying to run the first code with the Workbook_Open event and run the second code when a specific sheet is activated then you have a Worksheet_Activate event available to you.
 
Upvote 0
Thanks Firefyter!

I am getting closer to where I want to go. Using the template with your code results in the required name change to the content of cell AA2 BUT it also saves it instantly to the std location as set up in excel.

Is there any chance the code can be modified in such a way that it renames the file but does not save it yet? I would like to be flexible in where to store the file.

Thanks again,

Pete
 
Upvote 0
No, it's not possible. The file must be saved in order to change the name of it. You can keep it in the same location but saved with a different name, but that sounds like what you are trying to do.

One option maybe for you to browse for a folder to save the file to. Or you could always just open the SaveAs dialog box, either manually or via code.
 
Upvote 0
running 2 macro's

Thanks again Firefyter,

Major disappointment :confused: ........... OK, what next? How about I crate a button on my sheet and assign a macro to it that does the required name change and opens up the save as dialog box? Would not know how to do that though.......... This VBA stuff is not easy to get the hang of :)

any pointer on this one?

Pete
 
Upvote 0
Yeah, there are a lot of ways to do this. You could either go the long route, or just show the default dialog box ..

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> Show_SaveAs()
    Application.Dialogs(xlDialogSaveAs).Show "abc.xls"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

In this example, the "abc.xls" is the default name that will be shown in the name textbox. You can either omit that or change it to something you desire. A lot of folks ask for that when they ask to show the SaveAs dialog box (well, that's been my experience anyway).

There are plenty of other ways to do this as well.

HTH
 
Upvote 0
Firfytr,

OK. Thanks, trying to get it to do what I want.
Can abc.xls in the code - Show "abc.xls" - be replaced by the content of a specific cell. Something like Show "content of cell a1 on sheet 1"

I am quite sure I am asking for the impossible but you never know.......

Thanks again...............

Pete
 
Upvote 0
VICTORY!!!!!

Option Explicit

Sub Show_SaveAs()
Application.Dialogs(xlDialogSaveAs).Show Range("A1").Value

End Sub

Fist time I cracked something (very simple problem, but hey I am improving) after a pointer from Firefytr.

On to more chalanging problems!
 
Upvote 0

Forum statistics

Threads
1,217,448
Messages
6,136,688
Members
450,024
Latest member
Beagle263

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