Need help in Command button created in Excel

SunilSunny

New Member
Joined
Jul 23, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have created a command button in excel which when clicked opens a new email box. The code is as below.
What I want help is that when the button is clicked it opens the email box and automatically "To" field is filled (which should be picked from one cell of that excel sheet )

Private Sub CommandButton1_Click()
'Updated by Extendoffice 2017/9/14
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "" & vbNewLine & vbNewLine & _
"Regards" & vbNewLine & _
"Sunny"
On Error Resume Next
With xOutMail
.To = ActiveCell
.CC = "someone@xyz.com.au"
.BCC = ""

.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
 
Last edited by a moderator:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
t
ActiveCell.Value

Thanks for reply
When I use ActiveCell it only pick the value from the cell which is selected at that moment. I want the value to be picked form specific Cell only.
 
Upvote 0
.
You'll need to specifically name the cell you are referring to.
Example : Range("A1").Value ... or perhaps ... Sheet1.Range("A1").Value
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
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