ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Counter in Excel template (https://www.excelbanter.com/excel-programming/346378-counter-excel-template.html)

office newbie

Counter in Excel template
 
Hi,

Before I ask I did spend quite some time searching google groups so I
hope this is an interesting question for someone.

I am creating an template within excel for purchase orders and the user
will enter certain data which will be computed via formula no problem.

MY ISSUE is.....

I the template to hold some sort of counter value which will increment
each and every time a child document is created from it.

First time open counter or P.O. number is 1......second time is 2 etc etc.

This is regardless of whether the child document is saved or anything.

Upon spawning the child increment by one.....

Thanks in advance.

Leith Ross[_318_]

Counter in Excel template
 

Hello office newbie,

This counter will increment every time the template is opened. You ca
also use these same calls elsewhere in the code to increment the counte
if you need to. You can change the names template, opened, and counte
to whatever you like. The counter is stored in the Registry of th
machine it resides on. This insures the count will be accurate, even i
the program crashes.


Code
-------------------
Private Sub Workbook_Open()

Dim Cnt As Long

Cnt = Val(GetSetting("template", "opened", "counter"))
Cnt = Cnt + 1
SaveSetting "template", "opened", "counter", Str(Cnt)

End Sub

-------------------

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48751


office newbie

Counter in Excel template
 
FANTASTIC....

Thank you so much.

Have a wonderful holidays.


Leith Ross wrote:
Hello office newbie,

This counter will increment every time the template is opened. You can
also use these same calls elsewhere in the code to increment the counter
if you need to. You can change the names template, opened, and counter
to whatever you like. The counter is stored in the Registry of the
machine it resides on. This insures the count will be accurate, even if
the program crashes.


Code:
--------------------
Private Sub Workbook_Open()

Dim Cnt As Long

Cnt = Val(GetSetting("template", "opened", "counter"))
Cnt = Cnt + 1
SaveSetting "template", "opened", "counter", Str(Cnt)

End Sub

--------------------

Sincerely,
Leith Ross




All times are GMT +1. The time now is 10:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com