macro to display message,when open workbook

P

puiuluipui

Hi, i need a macro to display a message, first time i open workbook in new
month. If today is 01.11.2009, and i open my workbook, then, the macro to
display message "first day of the month,please save".
Sometime the first day of the month can be sunday, and i will open my
workbook, on the second day of the month, or another day. Can this macro be
made to display the message first time i open workbook in the new month?
Can this be done?
Thanks!
 
J

Jacob Skaria

Use the Workbook Open event.....and try the below code

Private Sub Workbook_Open()
If Format(FileDateTime(Me.FullName), "mmyy") <> _
Format(Date, "mmyy") Then MsgBox "first day of the month,please save"
End Sub

If this post helps click Yes
 
P

puiuluipui

Can you help me a little bit with how to use the Workbook Open event?
Thanks!

"Jacob Skaria" a scris:
 
J

Jacob Skaria

Here we go. From workbook press Alt+F11 to launch VBE (Visual Basic Editor).
From the left treeview search for the workbook name and click on + to expand
it. Within that you should see the following

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
This Workbook

Double click 'This WorkBook' and paste the below code to the right code pane.

If this post helps click Yes
 
P

puiuluipui

Hi Jacob, i paste the code into this workbook. i saved and closed everything.
i opened the workbook, but the macro didn't displayed any message. i closed
the workbook, set the time to 01.10.2009, and open again. nothing. what am i
doing wrong?
Thanks!

"Jacob Skaria" a scris:
 
J

Jacob Skaria

--The code checks whether ;the workbook has been saved in the current month
and if not it will pop-up the message
--Since you have already saved the file the current month it will not
display any message...Instead save;close the file and change the system date
to any date in the next month...and try opening the workbook

If this post helps click Yes
 
J

Jacob Skaria

Oops.. Please ignore the previous code...Try the below

Private Sub Workbook_Open()
If Format(Me.BuiltinDocumentProperties("Last Save Time"), "mmyy") <> _
Format(Date, "mmyy") Then MsgBox "first day of the month,please save"
End Sub

If this post helps click Yes
 
P

puiuluipui

Beautiful.
Thanks!

"Jacob Skaria" a scris:
Oops.. Please ignore the previous code...Try the below

Private Sub Workbook_Open()
If Format(Me.BuiltinDocumentProperties("Last Save Time"), "mmyy") <> _
Format(Date, "mmyy") Then MsgBox "first day of the month,please save"
End Sub

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top