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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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,214,561
Messages
6,120,234
Members
448,951
Latest member
jennlynn

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