I know it's a general question.
I am trying to create an application/extension that reads the contents of an email before it is sent out. So basically if the email contains a 8 character numerical for example, it will prompt an alert box whether the employee is sure before it is sent out.
I have worked with some Python outlook modules for myself. But my task would for it to be able to run on most employee desktops which wouldn't have Python installed.
I am looking at tools such as Visual Studio but am unsure where I should start.
You can develop a VBA macro or Outlook COM add-in (for example, VSTO based one) for that. See Walkthrough: Creating Your First VSTO Add-In for Outlook to get started quickly.
Basically you need to handle the ItemSend event of the Application class which is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program.
For example, here is a VBA sample code:
Public WithEvents myOlApp As Outlook.Application
Public Sub Initialize_handler()
Set myOlApp = Outlook.Application
End Sub
Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & Item.Subject & "?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
End If
End Sub
Finally, you may find the Getting Started with VBA in Outlook 2010 article helpful.
Related
I have made an userform excel system to SignUp or Login users to a kind of quizz. All this files are available on sharepoint of my company to be run. When someone SignUp, all information he had written in the userform are sent to an external workbook that gathered all users inscriptions. All works find individually, but when two people or more are submitting their signup data barely at the same time, their is a conflict in the external workbook because the users overwrite what the earliest one as putted into the cells while I asked to write in the next empty row. I think this is because, the external workbook has not the time to update on SharePoint what the very previous user as written.
To avoid this trubble, I have decide the CheckOut if an other user is already writting in the external workbook. However, I have a kind of similar issue with the CheckOut VBA code lines I used below. When the two users send their data barely at the same time, they come togather in the "CanCheckOut", then one of them succed to checkout the workbook, but the other one is bring to a message box who say "The workbook is already checkout. Would you like to open the file as readOnly or cancel file opening". My wish is that that only one of the users enter in the "If CanCheckOut Then", or to close automaticaly in VBA the messagebox for the second user trying to checkin. I don't know if I can avoid the two users to come inside this "if" because it could a standard lag of syncronisation due to SharePoint. So I tryed the second solution that is to close automaticaly in VBA the messagebox for the second user trying to checkin, however it seems that "Application.DisplayAlerts = False" or "On Error GoTo ErrorUser" don't work so I am kind of stuck and looking for your help and your experience in VBA with multi-users configurations on SharePoint to solve this issue.
Sub UseCheckOut()
Dim App As New Excel.Application
Dim wBook As Excel.Workbook
Dim FileNameUser As String
FileNameUser = ThisWorkbook.Path & "/Support/UsersData.xlsm"
If Workbooks.CanCheckOut(FileNameUser) = True Then
Workbooks.CheckOut FileNameUser ' When two users run the code simultaneously they
' both come to this line
Set wBook = App.Workbooks.Open(FileNameUser)
Else
MsgBox "Someone else signup to the quizz. Please, submit you registration again"
Exit Sub
End If
End Sub
On outlook application I created a new folder with name “Template”.
Inside that folder, I manually put some emails, with inside it my excel macro workbooks.
Macro settings on Excel are Disable all macros with notification, as a result when I open any macro workbook, I got a security warning that macros have been disabled, and I need to click Enable Content each time.
I could not find any way to add these files to a trusted location or even make as trusted document.
So, as a work around, I need to change excel macro settings (temporarily) from outlook when opening any email on that folder “Template” to Enable all macros and after close this email or sent it, then revert macro settings again to “Disable all macros with notification”.
Note 1, Sure, I mean change these macro settings # my machine only and not at the recipient PC.
Note 2, I already using some macros globally inside outlook (auto zoom), and signed these macros by creating a Digital Signature using SelfCert.exe، therefore I do not get any security warning when using that macros.
Note 3, I found this question Link, But I could not adapt the provided answer to my needs ,and I use office 2016 32Bit on windows 10 64Bit.
In advance grateful for useful comments and answer.
Public WithEvents myItem As Outlook.MailItem
Public EventsDisable as Boolean
Private Sub Application_ItemLoad(ByVal Item As Object)
If EventsDisable = True Then Exit Sub
If Item.Class = olMail Then
Set myItem = Item
End If
End Sub
Private Sub myItem_Open(Cancel As Boolean)
EventsDisable=True
'Your code
EventsDisable=False
End Sub
You'd be better off creating a VSTO COM addin in VB.Net - it will be able to work without prompts.
I have few shared mailbox in outlook. I created VBA in excel to extract out the email subject. But I have to click "Get Outlook" button in excel follow by click selected Inbox one by one. Is there any way that I able to schedule auto extract every each inbox instead of clicking it manually one by one?
Create a macro enabled workbook unless you have a suitable one available.
From the VBA Editor, click [Tools] then [References]. Check that "Microsoft Outlook nn.n Object Library" is listed near the top and ticked. If listed but not ticked, click the box to tick it. If not listed near the top, scroll down (the list is in alphabetic order) until you find this library and tick it.
Copy the code below to ThisWorkbook. Save the workbook and close it.
Open the workbook by clicking it or via Windows Scheduler. A list of the accessible stores is displayed as a demonstration. Click [OK] to exit Excel or [Cancel] to terminate the macro so you can work on the code. Warning 1: if you click [OK] all open workbooks will be closed without saving any changes. Warning 2: If you do not have a Cancel or equivalent option so the macro closes the workbook automatically, you will never be able to amend the macro.
Note: this code is a demonstration of using the Workbook Open event to run a macro and a demonstration of accessing Outlook from Excel. However, it does nothing with Outlook except list the accessible stores. If you need a further demonstration, I will try to help.
Option Explicit
Sub Workbook_Open()
' Needs reference to "Microsoft Outlook nn.n Object Library" where
' nn.n depends on the version of Outlook being used.
Dim Answer As Long
Dim Dspl As String
Dim InxS As Long
Dim OutApp As New Outlook.Application
Dim OutNs As Outlook.Namespace
Set OutNs = OutApp.Session
' Build list of all accessible stores
With OutNs
Dspl = .Folders(1).Name
For InxS = 2 To .Folders.Count
Dspl = Dspl & vbLf & .Folders(InxS).Name
Next
End With
Answer = MsgBox(Dspl, vbOKCancel)
If Answer = vbCancel Then
Exit Sub
End If
Application.DisplayAlerts = False
Application.Quit
End Sub
How can I receive an email notification every time a submission is made to an online Excel Survey?
You may subscribe as an alert to your email with the following steps:
Click on your document.
Choose File > Alert Me > Set alert on the document.
Choose your setting accordingly and DONE :)
However do not that, not only new subscription will trigger email, any changes will trigger email as well, sometime is quite annoying.
Try this. Forgive me as I don't have excel installed at home so I can't test to make sure it's right. This probably requires Outlook.
Sub CreateMail()
Dim myItem As Object
Set myItem = Application.CreateItem(olMailItem)
myItem.Subject = "Mail to myself"
myItem.To = "myself#myself.com"
myItem.body ="stuff"
myItem.send
End Sub
I created an Excel spreadsheet that my boss wants to put on the company's internal website. The spreadsheet contains some seldom-used, esoteric, but handy functions that only certain employees within the company will find really useful.
The problem is that I don't know who the future users are, and my boss wants me to identify who uses my spreadsheet.
He asked that I password-protect the Excel spreadsheet in such a way that one password does NOT unlock all of the copies that people can download from the site. For example, I can't just make the password "stackoverflow" because once a user legitimately gets the password from me, and is shared with other people, it can be used by anyone within the company to unlock all subsequently downloaded spreadsheets. I will never be able to ascertain who is using the spreadsheet. Also, I cannot modify the website, so I hope to achieve this tracking of users through Excel and email.
Is there a way to have Excel randomly generate a string, which the user emails me, and then I respond with the appropriate password that will unlock the file (based off the generated string)? This requires the user to check in with me before using the spreadsheet (the ideal situation).
Is such an arrangement possible in Excel 2010 Professional Plus?
I think password protection in the method you describe is unnecessarily cumbersome if it is even doable at all.
He asked that I password-protect the Excel spreadsheet in such a way that one password does NOT unlock all of the copies that people can download from the site.
I can't imagine how this might be possible using only Excel. Maybe an Add-in could do this, but at the file level, I don't think it could be done, at least not easily.
I will never be able to ascertain who is using the spreadsheet.
It sounds like this is the really important bit. You are not using the password as a security measure, only as a gatekeeping method to determine who is using the file. This can be automated in other ways, easiest of which would be to use certain Environment variables, e.g.:
MsgBox Environ("username") will display a message box with the current user's name.
You can assign Environ("username") to a string variable, and then you could for example automate Outlook to send you an email that "John Doe has opened the file", or something to that effect. If you want to avoid getting an email every time, you could do some tweaking with a Named Range variable in the Excel file, so that the macro will only send the email once, etc.
Alternatively, you may be able to write a log/txt file to a shared network location (of course, assuming the user is connected to the network) instead of sending emails.
Update
Here is some example code that I've taken from places around the web, it will send an email from the user. You will have to modify the sendTo lines to use your email address as recipient, etc.
Put this in the Workbook's code module, it should email you any time they open this file:
Option Explicit
Private Sub Workbook_Open()
' This example uses late-binding instead of requiring an add'l reference to the
' MS Outlook 14.0 Object Library.
Dim oApp As Object 'Outlook.Application 'Object
Dim ns As Object 'Namespace
Dim fldr As Object 'MAPIFolder
Dim mItem As Object 'Outlook.MailItem
Dim sendTo As Object 'Outlook.Recipient
Dim bOutlookFound As Boolean
On Error Resume Next
Set oApp = GetObject(, "Outlook.Application")
bOutlookFound = Err.Number = 0
On Error GoTo 0
If Not bOutlookFound Then Set oApp = CreateObject("Outlook.Application") 'New Outlook.Application
'# Set the namespace and folder so you can add recipients
Set ns = oApp.GetNamespace("MAPI")
Set fldr = ns.GetDefaultFolder(6) 'olFolderInbox
'# create an outlook MailItem:
Set mItem = oApp.CreateItem(0) 'olMailItem
'# assign a recipient
Set sendTo = mItem.Recipients.Add("YourName#Company.Com")
sendTo.Type = 1 'To olTo
'# assign another recipient
Set sendTo = mItem.Recipients.Add("YourManager#Company.Com")
sendTo.Type = 1
'# Validate the recipients (not necessary if you qualify valid email addresses:
For Each sendTo In mItem.Recipients
sendTo.Resolve
Next
mItem.Subject = "A user has opened the Excel file"
mItem.Body = "This is an automated message to inform you that " & _
Environ("username") & " has downloaded and is using the file."
mItem.Save
mItem.Send
'If outlook was not already open, then quit
If Not bOutlookFound Then oApp.Quit
Set oApp = Nothing
End Sub
Expanding on David's answer you could also use a macro that auto-runs when the sheet is opened and it could write Environ("username") to the next available row in a hidden worksheet. I've used Environ("username") before and it is quite useful, quick, and easy.
This sub on any worksheet will automatically run (IIRC):
Private Sub Auto_Open()
End Sub
You could also put a time stamp in the next column to show when the spreadsheet was used...