including voting buttons on my email

Davers

Well-known Member
Joined
Sep 17, 2002
Messages
1,165
I thought for sure I had posted this question here...but I can't seem to find it. :eek: I've created a "Time-Off Request Form" in Excel...so much nicer looking than HR's version they created in Word... :LOL: Anyway, "MY" version :LOL: creates an E-mail with the form in the body as html. And wouldn't it be cool if you could include the VotingOptions buttons on the e-mail so they could either "Accept" it or "Reject" it and have it send the response to the sender...well...I finally figure it out....I just needed to add one line to the code below:

Code:
Sub SendMail()

Module3.unlockSht
Worksheets("Sheet1").Select
Range("A1").Select

'Sends a specified range in an Outlook message and retains Excel formatting

'References needed :
'Microsoft Outlook Object Library
'Microsoft Scripting Runtime


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

nowTime = Format(Range("J4").Value, "dddd-dd-mmm-yyyy")
empName = Range("empName").Value

On Error Resume Next
Set rngeSend = Application.Range("C5:F47")

Set oFSObj = CreateObject("Scripting.FilesystemObject")
strTempFilePath = oFSObj.GetSpecialFolder(2)
strTempFilePath = strTempFilePath & "\XLRange.htm"

ActiveWorkbook.PublishObjects.Add(xlSourceRange, strTempFilePath, rngeSend.Parent.Name, rngeSend.Address, xlHtmlStatic).Publish True

Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(olMailItem)
Set FSObj = New Scripting.FileSystemObject
Set TStream = FSObj.OpenTextFile(strTempFilePath, ForReading)

strHTMLBody = TStream.ReadAll

TStream.Close
Kill strTempFilePath

olMail.HTMLBody = strHTMLBody
olMail.VotingOptions = "Accept;Reject"
olMail.Subject = ("Time off request for " & empName & nowTime)
'olMail.To = ("")
'olMail.CC = ("")
'Will display the e-mail before sending, otherwise it will just send
olMail.Display

'Close Objects
Set FSObj = Nothing
Set olApp = Nothing
Set olMail = Nothing
Set TStream = Nothing

Module3.lockSht

End Sub

The line I added was:
Code:
olMail.VotingOptions = "Accept;Reject"

It took me almost 5 days to figure out that tiny little line! :oops:

It actually creates the e-mail with the form as the body, and includes the voting buttons...which actually work!!! :p yay!!!

Just thought I'd post this in case anyone else ever wondered about those pesky voting buttons!

Have a good day, (y)

Dave M
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Thanks, Dave. I already have a possible project that could use an adaptation of this. (y)
 
Upvote 0

Forum statistics

Threads
1,215,009
Messages
6,122,674
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top