Auto_Open first time only via macro

dpoag

New Member
Joined
Mar 31, 2011
Messages
2
In Excel 10 I am currently using a short cut key (ctrl+i) that triggers a macro located in workbook A to open workbook B (which is a true template although it can be a regular workbook - I'm not opposed to that).

Workbook B has an Auto_Open macro that asks the user to name the workbook via a message box then saves the workbook based on cell contents.

I have done some research on this and created the code below which is working except for the fact that when I re-open the saved workbook it fires the Auto_Open again which messes things up. What can I do to alter the below code or what new code can I use to accomplish this? I want to avoid having to open the saved file from Excel by holding the Shift key. Many thanks.

Workbook A code:
Sub OpenIDS()
'
' OpenIDS Macro
'
' Keyboard Shortcut: Ctrl+i
'
Workbooks.Open Filename:= _
"C:\Users\Administrator\Documents\Custom Decorators\Window Installation Sheet (Garrett).xltm" _
, Editable:=True
ActiveWorkbook.RunAutoMacros xlAutoOpen
End Sub

Workbook B code:

Sub Auto_Open()
'
' Auto_Open Macro
'
l = InputBox("Type customer's name & scenario summary:")
Range("G1") = l
ActiveWorkbook.SaveAs Filename:="C:\Users\Administrator\Documents\Custom Decorators\Installation Detail Sheets\" _
& Range("G1").Value & ".xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
'
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Why don't you put the SaveAs into the code in workbook A? (including the other code you now store in workbook B - so there should be no code in B).
 
Upvote 0
Because I like to complicate things I guess! Thank you for the simple suggestion and it worked of course.
 
Upvote 0
True, you should never complicate things. For instance, your initial workbook B code could easily be:

Code:
Sub Auto_Open()
'
' Auto_Open Macro
'
    ActiveWorkbook.SaveAs Filename:="C:\Users\Administrator\Documents\Custom Decorators\Installation Detail Sheets\" _
        & InputBox("Type customer's name & scenario summary:") & ".xlsm", _
        FileFormat:=xlOpenXMLWorkbookMacroEnabled
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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