Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending an email from excel with VBA as review not attachment

Status
Not open for further replies.

kitackers

MIS
Apr 16, 2004
33
GB
I've got a spreadsheet that gets completed and sent to a group of people on the click of a button, which is

Sub Mail_workbook()
ActiveWorkbook.SendMail "xxx_xxxxx@xxxxx.co.uk", _
"Daily Absence Log" & " " & Now()

End Sub

Nice an simple and does the job!

Is there a way of changing this so the spreadsheet gets sent as a preview rather than an attachment (we use Microsoft outlook if that matters)

Also, I've gone through a few of the FAQ's to see if there is a way to stop the warning coming up about "a progamme is trying to send an email automatically on your behalf" but can't get anything to work with the code I'm using.

Any suggestions
 
I use the following code

Code:
Public Sub Email()

Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim FSObj As Scripting.FileSystemObject
Dim TStream As Scripting.TextStream
Dim rngeSend As Range
Dim strHTMLBody As String


'Select the range to be sent
On Error Resume Next
Set rngeSend = Application.InputBox("Please select range you wish to send.", , , , , , , 8)
If rngeSend Is Nothing Then Exit Sub    'User pressed Cancel
On Error GoTo 0

'Now create the HTML file
ActiveWorkbook.PublishObjects.Add(xlSourceRange, "C:\sales\tempsht.htm", rngeSend.Parent.Name, rngeSend.Address, xlHtmlStatic).Publish True


'Create an instance of Outlook (or use existing instance if it already exists
Set olApp = CreateObject("Outlook.Application")

'Create a mail item
Set olMail = olApp.CreateItem(olMailItem)

'Open the HTML file using the FilesystemObject into a TextStream object
Set FSObj = New Scripting.FileSystemObject
Set TStream = FSObj.OpenTextFile("C:\sales\tempsht.htm", ForReading)

'Now set the HTMLBody property of the message to the text contained in the TextStream object
strHTMLBody = TStream.ReadAll

olMail.HTMLBody = strHTMLBody
olMail.To = "anybody@anywhere.com"
olMail.Subject = "HTML Email"
olMail.Send


End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top