Adding a random signature to Outlook 2013
I was looking for a way to have a random signature in my mail (outlook). I didn't think I should need to resort to a full blown plugin/download to just do this simple task.
You can do this via the Developer tab in the Office Outlook client. If you dont have the developer ribon active you will have to enable it. You can do this via Options -> Customize Ribbon -> Tick the "Developer" checkbox and click OK. After adding it, go to the developer ribbon and click the "Visual Basic" button to go to the devekioer editor. Paste the following script in the "ThisOutlookSession" file.
Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If Item.Class <> olMail Then Exit Sub 'Make sure it's a send mail Const SearchString = "%Random_Line%" Const QuotesFile = "d:\quotes.txt" ' Path to file containing a quote per line If InStr(Item.Body, SearchString) Then If FileOrDirExists(QuotesFile) = False Then MsgBox ("Quotes file not found!") Cancel = True Else Dim lines() As String Dim numLines As Integer numLines = 0 ' Open the file for reading Open QuotesFile For Input As #1 ' Go over each line in the file and save it in the array + count it Do Until EOF(1) ReDim Preserve lines(numLines + 1) Line Input #1, lines(numLines) numLines = numLines + 1 Loop Close #1 ' Get the random line number Dim randLine As Integer randLine = Int(numLines * Rnd()) + 1 ' Insert the random quote Item.HTMLBody = Replace(Item.HTMLBody, SearchString, lines(randLine)) End If End If End Sub Function FileOrDirExists(PathName As String) Dim iTemp As Integer On Error Resume Next iTemp = GetAttr(PathName) Select Case Err.Number Case Is = 0 FileOrDirExists = True Case Else FileOrDirExists = False End Select On Error GoTo 0 End Function |
This will replace the phrase %Random_Line% with a random line from the text file. If it can't open the text file it will not send the email out. Now you just need to edit your signature and place %Random_Line% where you like.
Please Register.
If you wish to add comments.
Cheers
Adam