• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

VBA Emails hard code sheet & template name|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / VBA Emails hard code sheet & template name|VBA & Macros|Excel Forum|My Online Training Hub

vba course banner

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosVBA Emails hard code sheet & te…
sp_PrintTopic sp_TopicIcon
VBA Emails hard code sheet & template name
Avatar
Sherry Fox
Poinciana, FL
Member
Members
Level 0
Forum Posts: 77
Member Since:
December 4, 2021
sp_UserOnlineSmall Online
1
April 22, 2023 - 6:16 am
sp_Permalink sp_Print

I have this code, but I need to alter it, and I am not sure how.  I need it to do the follow:

1.  Access a template rather than a traditional plain email.  Path & file name below

C:\Users\barnes22\AppData\Roaming\Microsoft\Templates\VOC.oft

2.  Not use an input box for the range.   I would like that sheet name and range to be hardcoded in the VBA "SurveyVoC" is the sheet, and B2:B500 is the range

Sub sendmultiple()
Dim xOTApp As Object
Dim xMItem As Object
Dim xCell As Range
Dim xRg As Range
Dim xEmailAddr As String
Dim xTxt As String
On Error Resume Next
xTxt = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Please select the addresses list"
If xRg Is Nothing Then Exit Sub
Set xOTApp = CreateObject("Outlook.Application")
For Each xCell In xRg
If xCell.Value Like "*@*" Then
If xEmailAddr = "" Then
xEmailAddr = xCell.Value
Else
xEmailAddr = xEmailAddr & ";" & xCell.Value
End If
End If
Next
Set xMItem = xOTApp.CreateItem(0)
With xMItem
.To = xEmailAddr
.Display
End With
End Sub

Avatar
Hans Hallebeek
the Netherlands
Member
Members
Level 0
Forum Posts: 121
Member Since:
October 17, 2018
sp_UserOfflineSmall Offline
2
April 23, 2023 - 4:55 pm
sp_Permalink sp_Print

Hi, I hope this makes sense:

[code]

Sub sendmultiple()
Const mailTemplate As String = "C:\Users\barnes22\AppData\Roaming\Microsoft\Templates\VOC.oft"
Const mailSheet As String = "SurveyVoC"
Dim wb As Workbook
Dim ws As Worksheet
Dim xOTApp As Object
Dim xMItem As Object
Dim xCell As Range
Dim xRg As Range
Dim xEmailAddr As String
Dim xTxt As String
On Error Resume Next
Set wb = ThisWorkbook
Set ws = wb.Worksheets(mailSheet)
'* You will have to set the worksheet's range that contains the email addresses here
Set xRg = ws.Range("A2:A" & ws.Cells(Rows.Count, "A").End(xlUp).Row)

'xTxt = ActiveWindow.RangeSelection.Address
'Set xRg = Application.InputBox("Please select the addresses list"
If xRg Is Nothing Then Exit Sub
xEmailAddr = ""
For Each xCell In xRg
If xCell.Value Like "*@*" Then
If xEmailAddr = "" Then
xEmailAddr = xCell.Value
Else
xEmailAddr = xEmailAddr & ";" & xCell.Value
End If
End If
Next
If xEmailAddr <> "" Then
Set xOTApp = CreateObject("Outlook.Application")
Set xMItem = xOTApp.CreateItem(0)
With xMItem
.To = xEmailAddr
.Display
End With
End If

End Sub

[/code]

Avatar
Sherry Fox
Poinciana, FL
Member
Members
Level 0
Forum Posts: 77
Member Since:
December 4, 2021
sp_UserOnlineSmall Online
3
April 25, 2023 - 12:17 am
sp_Permalink sp_Print sp_EditHistory

That did not quite work.  First, it did not work out as planned.  The template (VOC.oft) was not accessed, only a normal "white" email opened.  I verified the path and it is correct.  Also, I changed the column from A to B, as B is where the email addresses are.  But my form contains over 6K emails, all of which were placed on the email, and the email stated it would only be sent to 500 people.  What did I do wrong???

Sub sendmultipleForum()
Const mailTemplate As String = "C:\Users\barnes22\AppData\Roaming\Microsoft\Templates\VOC.oft"
Const mailSheet As String = "SurveyVoC"
Dim wb As Workbook
Dim ws As Worksheet
Dim xOTApp As Object
Dim xMItem As Object
Dim xCell As Range
Dim xRg As Range
Dim xEmailAddr As String
Dim xTxt As String
On Error Resume Next
Set wb = ThisWorkbook
Set ws = wb.Worksheets(mailSheet)
'* You will have to set the worksheet's range that contains the email addresses here
Set xRg = ws.Range("B2:B" & ws.Cells(Rows.Count, "B").End(xlUp).Row)
'xTxt = ActiveWindow.RangeSelection.Address
'Set xRg = Application.InputBox("Please select the addresses list"
If xRg Is Nothing Then Exit Sub
xEmailAddr = ""
For Each xCell In xRg
If xCell.Value Like "*@*" Then
If xEmailAddr = "" Then
xEmailAddr = xCell.Value
Else
xEmailAddr = xEmailAddr & ";" & xCell.Value
End If
End If
Next
If xEmailAddr <> "" Then
Set xOTApp = CreateObject("Outlook.Application")
Set xMItem = xOTApp.CreateItem(0)
With xMItem
.To = xEmailAddr
.Display
End With
End If
End Sub
Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 648
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
4
April 25, 2023 - 12:48 am
sp_Permalink sp_Print

Set xMItem = xOTApp.CreateItem(0)

should be:

Set xMItem = xOTApp.CreateItemFromTemplate(mailTemplate)

 

I suspect (hope) Outlook will not allow you to put 6k email addresses into the To field.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Philip Treacy, Sherry Fox
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 216
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Melanie Ford
Isaac Felbah
Adele Glover
Hitesh Asrani
Rohan Abraham
Anthony van Riessen
Erlinda Eloriaga
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Forum Stats:
Groups: 3
Forums: 24
Topics: 6356
Posts: 27793

 

Member Stats:
Guest Posters: 49
Members: 32324
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.