COUNT= number of times opened?

npacker

Board Regular
Joined
Oct 14, 2004
Messages
132
Hi all,
Bear with me here. I have a template that when a user opens it, I have code that automatically does a save as to a different file name in a different folder. But the problem is, I don't want that code to run if the user then goes and opens that file later on. I only want it to run the first time they open the template. I thought maybe I could have it count the number of times it has been opened, and if it is equal to or greater than 1, then not run the code, but then I realized it might restart the count every time they opened that newly saved file every time.

Could I have it save the count to a cell in an invisible sheet, and the pull it from there every time?

I think that would work, but I don't know how to implement the count code on open. Please help!
Nate
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
what about a line like:

If ActiveWorkbook.Name <> "Template.xls" Then Exit Sub

So it'll skip the Open macro if it's not the template...
 
Upvote 0
Could you use the user name? Write it to a value (cell, registry, etc) then check it upon open? If the current name is not equal to the saved name, run code, else don't run. ??

Here is a good example of getting different user name variables ...

http://www.vbaexpress.com/kb/getarticle.php?kb_id=234

Edit: The only problem with a name check with the original name is dependent on how susceptible the workbook is to name changes. If it will be Saved As at any point, or is an actual template file, I'd suggest another route. Possibly the user name route.
 
Upvote 0
How about test for the workbook name instead:

<font face=Tahoma><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Open()
    <SPAN style="color:#00007F">If</SPAN> ActiveWorkbook.Name = "Template.xls" <SPAN style="color:#00007F">Then</SPAN>
        <SPAN style="color:#007F00">'   Run SaveAs code</SPAN>
    Else: <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,

Smitty
 
Upvote 0
That is a great idea, I didn't even think of that, that's perfect. I'll do that.
Thanks,
Nate
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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