Send mail with link to workbook
Important read this :
The code on this page is only working with Outlook and not with Outlook Express or Windows Mail.
If you not use Outlook see the examples in the first section on my mail index page.
Copy the code in a Standard module, if you just started with VBA see this page.
http://www.rondebruin.nl/code.htm
Check out this page for Tips If you want to change the code on this page.
http://www.rondebruin.nl/mail/tips2.htm
Example
If you want to let your Colleagues/Co workers now that you have created a workbook that you want to
share with them you can use the following subroutine to create a mail with a link to the ActiveWorkbook.
Important :
1: The ActiveWorkbook must be saved on a drive that everyone is connected to
2: The reciever of the mail must also use Outlook
Change the mail address in the macro before you run it.
Tip: If you want that certain code is available in all your workbooks, then use your PERSONAL.XLS
or in Excel 2007-2010 your PERSONAL.XLSB file. You can use the same macro then for every file.
See: http://www.rondebruin.nl/personal.htm
Early Binding
If you want to use the the Intellisense help showing you the properties and methods of the objects as you
type you can use Early binding. (bit faster but have problems when you distribute your workbooks)
See Dick's site for a explanation
http://www.dicks-clicks.com/excel/olBinding.htm
Add a reference to the Microsoft outlook Library
1) Go to the VBA editor, Alt -F11
2) Tools>References in the Menu bar
3) Place a Checkmark before Microsoft Outlook ? Object Library
? is the Excel version number
Then replace this three lines in the code
Dim OutApp As Object
Dim OutMail As Object
Set OutMail = OutApp.CreateItem(0)
With this three
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutMail = OutApp.CreateItem(olMailItem)
The code on this page is only working with Outlook and not with Outlook Express or Windows Mail.
If you not use Outlook see the examples in the first section on my mail index page.
Copy the code in a Standard module, if you just started with VBA see this page.
http://www.rondebruin.nl/code.htm
Check out this page for Tips If you want to change the code on this page.
http://www.rondebruin.nl/mail/tips2.htm
Example
If you want to let your Colleagues/Co workers now that you have created a workbook that you want to
share with them you can use the following subroutine to create a mail with a link to the ActiveWorkbook.
Important :
1: The ActiveWorkbook must be saved on a drive that everyone is connected to
2: The reciever of the mail must also use Outlook
Change the mail address in the macro before you run it.
Sub Make_Outlook_Mail_With_File_Link() 'Working in Office 2000-2010 Dim OutApp As Object Dim OutMail As Object Dim strbody As String If ActiveWorkbook.Path <> "" Then Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) strbody = "<font size=""3"" face=""Calibri"">" & _ "Colleagues,<br><br>" & _ "I want to inform you that the next sales Order :<br><B>" & _ ActiveWorkbook.Name & "</B> is created.<br>" & _ "Click on this link to open the file : " & _ "<A HREF=""file://" & ActiveWorkbook.FullName & _ """>Link to the file</A>" & _ "<br><br>Regards," & _ "<br><br>Account Management</font>" On Error Resume Next With OutMail .To = "ron@debruin.nl" .CC = "" .BCC = "" .Subject = ActiveWorkbook.Name .HTMLBody = strbody .Display 'or use .Send End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing Else MsgBox "The ActiveWorkbook does not have a path, Save the file first." End If End Sub
Tip: If you want that certain code is available in all your workbooks, then use your PERSONAL.XLS
or in Excel 2007-2010 your PERSONAL.XLSB file. You can use the same macro then for every file.
See: http://www.rondebruin.nl/personal.htm
Early Binding
If you want to use the the Intellisense help showing you the properties and methods of the objects as you
type you can use Early binding. (bit faster but have problems when you distribute your workbooks)
See Dick's site for a explanation
http://www.dicks-clicks.com/excel/olBinding.htm
Add a reference to the Microsoft outlook Library
1) Go to the VBA editor, Alt -F11
2) Tools>References in the Menu bar
3) Place a Checkmark before Microsoft Outlook ? Object Library
? is the Excel version number
Then replace this three lines in the code
Dim OutApp As Object
Dim OutMail As Object
Set OutMail = OutApp.CreateItem(0)
With this three
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutMail = OutApp.CreateItem(olMailItem)