How many times a spreadsheet is opened

nathank

New Member
Joined
Sep 11, 2002
Messages
14
Hello,

We have excel spreadsheets that we have to update every year due to wage changes. There are thousands of them. I was hoping to be able to designate a cell eg A400 to count how many times the file has been opened. If it is 0 I am not going to update.

Regards

Nathan Kennedy
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

kskinne

Well-known Member
Joined
Feb 17, 2002
Messages
1,267
Office Version
  1. 365
Platform
  1. Windows
right-click on the excel icon to the left of the word 'file' on the left of the menu bar. select 'view code'. double-click on 'this workbook', and place the following code into the workbook's object window:

Private Sub Workbook_Open()
Range("A400").Value = Range("A400").Value + 1
ActiveWorkbook.Save
End Sub

this code will add one to the value in A400 each time the workbook is opened, and then save the workbook.

HTH
kevin
 

kskinne

Well-known Member
Joined
Feb 17, 2002
Messages
1,267
Office Version
  1. 365
Platform
  1. Windows
you could further modify this code to give you a message upon opening:

Private Sub Workbook_Open()
Range("A400").Value = Range("A400").Value + 1
Times_Opened = Range("A400").Value
MsgBox ("This file has been opened " & Times_Opened & " times.")
ActiveWorkbook.Save
End Sub
 

PaddyD

MrExcel MVP
Joined
May 1, 2002
Messages
14,234
In an entirely 'groundhog day' moment - don't forget to protect the cell! Who can remember the link to ozgrid?

Paddy
 

kskinne

Well-known Member
Joined
Feb 17, 2002
Messages
1,267
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

but if you protect the cell, won't that prevent the macro from running properly and editing the cell as it should?

kevin
 

PaddyD

MrExcel MVP
Joined
May 1, 2002
Messages
14,234
not if you used the "less than fool-proof" method of using data validation & setting the check to

=len(a400)=""

This will stop users overtyping the value ("protection" of sorts), while allowing the macro to do its thing...

Paddy
 

kskinne

Well-known Member
Joined
Feb 17, 2002
Messages
1,267
Office Version
  1. 365
Platform
  1. Windows
i see what you are saying Paddy - good point

kevin
 

Forum statistics

Threads
1,144,510
Messages
5,724,781
Members
422,578
Latest member
annsalinas

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
Top