Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8437609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:28:48+00:00 2026-06-10T07:28:48+00:00

I am have the following code for excel vba that will email a range

  • 0

I am have the following code for excel vba that will email a range of addresses in my sheet. Howeve, I am looking to maybe use an inputbox to determine what the range is that I would like to email. The trouble i run into is getting the input to become a value that the function mailid understands. any suggestions?

Sub EmailActiveSheetWithOutlook2()

Dim oApp, oMail As Object, _
tWB, cWB As Workbook, _
FileName, FilePath As String

Application.ScreenUpdating = False

'Set email id here, it may be a range in case you have email id on your worksheet

 Sheets("Sheet1").Select
 mailId = Range("b4:b5").Value


'Write your email message body here , add more lines using & vbLf _ at the end of each line

Body = "Hello, it appears you have not yet filled out the transportation contact information excel sheet. This sheet was emailed to you, please complete this and send to me  saved as your firstnamelastname.xls at your earliest convience." & vbLf _
& vbLf _
& "Thanks & Regards" & vbLf _
& vbLf _
& "-Ryan " & vbLf _

‘Sending email through outlook

Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
    .To = mailid
    .Subject = "Transportation Committee Notice"
    .Body = Body
    '.Attachments.Add tWB.FullName
    .send
End With


End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:28:50+00:00Added an answer on June 10, 2026 at 7:28 am

    To replicate the effect of your current code use

    mailid = Application.InputBox(Prompt:="Select Range", Type:=8)
    

    where Type:=8 specifies a return type of Range. This returns the Value property of the selected range into mailid

    Alternatively use

    Dim rng as Range
    Set rng = Application.InputBox(Prompt:="Select Range", Type:=8)
    mailid = rng.Value
    

    rng is then set to the selected range, and can be validated before use

    Note that you should add error handling to account for, eg user Cancelling the InputBox

    Do not set Application.ScreenUpdating = False before issuing InputBox as this will prevent the user interacting with the screen.

    As an aside, your code uses Dim incorrectly: Dim‘ing a variable without a As clause declares it as `Variant.
    eg

    Dim oApp, oMail As Object
    

    actually declares oApp as a Variant, use

    Dim oApp As Object, oMail As Object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Win-XP / Excel 2003 / VBA .... I have the following piece of code
I have something of the following : Sheet 1 (Name Range : Code) Column
I have the following VBA code: mainFile = ActiveWorkbook.Name 'select all excel files in
I have the following VBA code inside an Excel macro: With ActiveSheet.QueryTables.Add( _ Connection:=ConnStr,
In Excel 2007 I have the following very simple code in VBA: Public Type
I have the following VBA code within excel. It's goal is to remove a
I have the following code: Excel.Range range = workSheet.UsedRange; for (rowCount = 2; rowCount
I have the following code in VBA (which resides in an Excel 2007 Workbook):
I'm doing a small app in Excel, and I have the following code when
I have following code that I am compiling in a .NET 4.0 project namespace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.