PDA

View Full Version : open workbook



apple
09-08-2008, 06:24 AM
Hello,:hi:

Can anyone help me VBA as below:

1) Once user open the worksheet, email will
notify me that worksheet is opening by user
2) When user close the worksheet, another email inform me that worksheet already close by user

Thanks and hope to hear from you soon

Bob Phillips
09-08-2008, 06:29 AM
What email client are you using?

apple
09-08-2008, 06:37 AM
Hi Xld,

i am using miscrosoft outlook 2003. Basically i want to know user open my worksheet and when close my worksheet. After user key in the data, they will close the worksheet. Notification mail to me, will help me update the data that user key in immediately.

Bob Phillips
09-08-2008, 07:37 AM
Private Sub Workbook_BeforeClose(Cancel As Boolean)
EmailMe Environ("Username") & " has closed the workbook at " & Format(Now, "dd-mmm-yyy hh:mm:ss")
End Sub

Private Sub Workbook_Open()
EmailMe Environ("Username") & " has opened the workbook at " & Format(Now, "dd-mmm-yyy hh:mm:ss")
End Sub

Private Sub EmailMe(ByVal Subject As String)
Dim oOutlook As Object
Dim oMailItem As Object
Dim oRecipient As Object
Dim oNameSpace As Object

Set oOutlook = CreateObject("Outlook.Application")
Set oNameSpace = oOutlook.GetNameSpace("MAPI")
oNameSpace.Logon , , True

Set oMailItem = oOutlook.CreateItem(0)
Set oRecipient = _
oMailItem.Recipients.Add("apple@apple.com")
oRecipient.Type = 1
With oMailItem
.Subject = Subject
.Send
End With

End Sub


This is workbook event code.
To input this code, right click on the Excel icon on the worksheet
(or next to the File menu if you maximise your workbooks),
select View Code from the menu, and paste the code

apple
09-08-2008, 07:56 AM
Good Day Xld,

Thank you very much:bow:. I will try it.