Send Mail with InputBox

mrowe

Board Regular
Joined
Feb 17, 2002
Messages
232
Hi,

I've used the following code (partly from a previous posting) to send my sheet via email to a specfic user. What I would like to know is how to use an input box to send the sheet to who ever the user want to. Creating the Input Box is easy, it's how I define a variable that I don't know.

Thanks


Range("A1").Select
Selection.CurrentRegion.Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.SendMail Recipients:="matthew.rowe@tmp.com", Subject:="PIPELINE", ReturnReceipt:=True
MsgBox "Your Request Has Been Sent", , "MESSAGE"
ActiveWindow.Close
Sheets("Enter_NEW_Record").Select
Range("D17:F17").Select
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.SendMail Recipients:="matthew.rowe@tmp.com", Subject:="PIPELINE", ReturnReceipt:=True
MsgBox "Your Request Has Been Sent", , "MESSAGE"
ActiveWindow.Close
Sheets("Enter_NEW_Record").Select
Range("D17:F17").Select
End Sub

OK dokes, you would put something like this at the start of your code:

<pre>
'Declare String
Dim sAddress As String

'Initialise the string with the address entered into box
sAddress = InputBox("Enter email address", "Send To")
'If the user doesn't enter an address then exit the sub.
If sAddress = "" Then Exit Sub

</pre>

This does not check to see if the user has put in a valid email address, but it does check to make sure the user put in something.

Then instead of "Martin.Rowe@tmp.com" you would put in:

<pre>
Recipients:=sAddress
</pre>

HTH
 
Upvote 0

Forum statistics

Threads
1,223,350
Messages
6,171,592
Members
452,412
Latest member
sprichwort

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