Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Send Mail with InputBox

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Posts
    232
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  2. #2
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default


    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:


    '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



    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:


    Recipients:=sAddress


    HTH

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Posts
    232
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks alot! It works a treat.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •