Make VBA sub available to any workbook
I have a very simple sub I have written in VBA and I would like to have it
available in every workbook I open without inserting the code in each one.
My preference would be to have it called by a custom toolbar button, but I'll
take just about anything. Is this possible and if so, any pointers on how to
actually do it?
I have attached the sub in question:
Private Sub SaveAndSend()
Dim thisSheet As Worksheet
Dim strName As String
Dim strFullPath As String
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.MailItem
Dim bPos As Byte
Set thisSheet = ThisWorkbook.ActiveSheet
bPos = InStr(1, ThisWorkbook.Name, ".xls")
strName = Mid(ThisWorkbook.Name, 1, bPos) & thisSheet.Name
strFullPath = Application.GetSaveAsFilename(strName, "Microsoft Office
Excel Workbook (*.xls), *.xls")
If strFullPath = "False" Then
MsgBox "Canceled by the user"
Else
thisSheet.SaveAs (strFullPath)
Set myItem = myOlApp.CreateItem(olMailItem)
myItem.Subject = strName
myItem.BodyFormat = olFormatHTML
myItem.HTMLBody = "<a href=file:///" & strFullPath & "" & strName &
"</a"
myItem.Display
End If
End Sub
|