A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Monthly E-Mails



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 22nd 08, 07:41 PM posted to microsoft.public.outlook.program_vba
Gabe
external usenet poster
 
Posts: 18
Default Monthly E-Mails

I have some code that automatically sends e-mails each month to different
poeple. Each month the e-mails are different (for example: In January I send
2 e-mails and in Febuary I send 3 e-mails). So now I have been forced to make
a separate code under a different module for each month of the year. The
problem is that when I have to add a new e-mail contact to the list, I have
to spend hours changing each code(one for each month of the year). Is there a
way to make only one code but then specify who to include in each month? So
that I can just change 1 code and not 12? Here is an example of what it looks
like:

Sub January()'Module 1
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
End Sub


Sub Febuary()'Module 2
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
End Sub
Ads
  #2  
Old February 25th 08, 07:18 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Monthly E-Mails



Month(Date) tells you the current month.

--
Best regards
Michael Bauer - MVP Outlook
Use Outlook Categories? This is Your Tool:
http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Fri, 22 Feb 2008 10:41:03 -0800 schrieb Gabe:

I have some code that automatically sends e-mails each month to different
poeple. Each month the e-mails are different (for example: In January I

send
2 e-mails and in Febuary I send 3 e-mails). So now I have been forced to

make
a separate code under a different module for each month of the year. The
problem is that when I have to add a new e-mail contact to the list, I

have
to spend hours changing each code(one for each month of the year). Is

there a
way to make only one code but then specify who to include in each month?

So
that I can just change 1 code and not 12? Here is an example of what it

looks
like:

Sub January()'Module 1
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
End Sub


Sub Febuary()'Module 2
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
End Sub

  #3  
Old March 10th 08, 06:29 PM posted to microsoft.public.outlook.program_vba
Gabe
external usenet poster
 
Posts: 18
Default Monthly E-Mails

I am just learning VBA, really just a beginner... how/where would I specify
each e-mail to be sent on a particular month(s) of the year using the
month(date) procedure? Thanks for all of your help. It is very much
appriciated.

~Gabe

"Michael Bauer [MVP - Outlook]" wrote:



Month(Date) tells you the current month.

--
Best regards
Michael Bauer - MVP Outlook
Use Outlook Categories? This is Your Tool:
http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Fri, 22 Feb 2008 10:41:03 -0800 schrieb Gabe:

I have some code that automatically sends e-mails each month to different
poeple. Each month the e-mails are different (for example: In January I

send
2 e-mails and in Febuary I send 3 e-mails). So now I have been forced to

make
a separate code under a different module for each month of the year. The
problem is that when I have to add a new e-mail contact to the list, I

have
to spend hours changing each code(one for each month of the year). Is

there a
way to make only one code but then specify who to include in each month?

So
that I can just change 1 code and not 12? Here is an example of what it

looks
like:

Sub January()'Module 1
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
End Sub


Sub Febuary()'Module 2
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
End Sub


  #4  
Old March 11th 08, 04:11 AM posted to microsoft.public.outlook.program_vba
JP[_3_]
external usenet poster
 
Posts: 201
Default Monthly E-Mails

I think what Michael was suggesting was something like a Select Case
statement. When you run the code it would automatically pick up the
current month (from the current date) and select the appropriate
recipients. Something like this:

Sub SendMonthlyMsgs()

Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Dim strRecip As Outlook.Recipient

Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)

' what month is it?
Select Case Month(Date)
Case 1 ' January
strRecip = "John Smith; Mary Jones"
Case 2 ' February
strRecip = "John Smith; Mary Jones;Mark Summers"
Case 3 ' March
strRecip = "John Smith; Mary Jones;Mark Summers;Jane Doe"

' ------------------
' more Case statements here
'------------------

End Select

With olMsg
.To = strRecip
.Subject = "Monthly Report"
.Display
End With

End Sub



On Mar 10, 1:29*pm, Gabe wrote:
I am just learning VBA, really just a beginner... how/where would I specify
each e-mail to be sent on a particular month(s) of the year using the
month(date) procedure? Thanks for all of your help. It is very much
appriciated.

~Gabe

"Michael Bauer [MVP - Outlook]" wrote:





Month(Date) tells you the current month.


--
Best regards
Michael Bauer - MVP Outlook
* Use Outlook Categories? This is Your Tool:
* http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6


Am Fri, 22 Feb 2008 10:41:03 -0800 schrieb Gabe:


I have some code that automatically sends e-mails each month to different
poeple. Each month the e-mails are different (for example: In January I

send
2 e-mails and in Febuary I send 3 e-mails). So now I have been forced to

make
a separate code under a different module for each month of the year. The
problem is that when I have to add a new e-mail contact to the list, I

have
to spend hours changing each code(one for each month of the year). Is

there a
way to make only one code but then specify who to include in each month?

So
that I can just change 1 code and not 12? Here is an example of what it

looks
like:


Sub January()'Module 1
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
* *.To = "
* *.Subject = "Monthly Report"
* *.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
* *.To = "
* *.Subject = "Monthly Report"
* *.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
End Sub


Sub Febuary()'Module 2
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
* *.To = "
* *.Subject = "Monthly Report"
* *.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
* *.To = "
* *.Subject = "Monthly Report"
* *.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
* *.To = "
* *.Subject = "Monthly Report"
* *.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
End Sub- Hide quoted text -


- Show quoted text -


  #5  
Old March 11th 08, 05:53 PM posted to microsoft.public.outlook.program_vba
Gabe
external usenet poster
 
Posts: 18
Default Monthly E-Mails

Hmmm...Actually there are 10 seperate messages all with different recipients
that I send each month. Each procedure varies by month, for example: I send 5
messages in Jan, then I send 7 messages in Feb etc...Is there a way to
specify the message itself so that I can see which months each message is
being sent? Kinda like this,

If month(date) = 1,3,4,5,6,7,8,9,10,11,12 Then 'If the current date matches
any of these months, then send this message
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With

If month(date) = 1,5,6,7,8,9,10,11,12 Then 'If the current date matches any
of these months, then send this message
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With



"JP" wrote:

I think what Michael was suggesting was something like a Select Case
statement. When you run the code it would automatically pick up the
current month (from the current date) and select the appropriate
recipients. Something like this:

Sub SendMonthlyMsgs()

Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Dim strRecip As Outlook.Recipient

Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)

' what month is it?
Select Case Month(Date)
Case 1 ' January
strRecip = "John Smith; Mary Jones"
Case 2 ' February
strRecip = "John Smith; Mary Jones;Mark Summers"
Case 3 ' March
strRecip = "John Smith; Mary Jones;Mark Summers;Jane Doe"

' ------------------
' more Case statements here
'------------------

End Select

With olMsg
.To = strRecip
.Subject = "Monthly Report"
.Display
End With

End Sub



On Mar 10, 1:29 pm, Gabe wrote:
I am just learning VBA, really just a beginner... how/where would I specify
each e-mail to be sent on a particular month(s) of the year using the
month(date) procedure? Thanks for all of your help. It is very much
appriciated.

~Gabe

"Michael Bauer [MVP - Outlook]" wrote:





Month(Date) tells you the current month.


--
Best regards
Michael Bauer - MVP Outlook
Use Outlook Categories? This is Your Tool:
http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6


Am Fri, 22 Feb 2008 10:41:03 -0800 schrieb Gabe:


I have some code that automatically sends e-mails each month to different
poeple. Each month the e-mails are different (for example: In January I
send
2 e-mails and in Febuary I send 3 e-mails). So now I have been forced to
make
a separate code under a different module for each month of the year. The
problem is that when I have to add a new e-mail contact to the list, I
have
to spend hours changing each code(one for each month of the year). Is
there a
way to make only one code but then specify who to include in each month?
So
that I can just change 1 code and not 12? Here is an example of what it
looks
like:


Sub January()'Module 1
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
End Sub


Sub Febuary()'Module 2
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With
Set olMsg = Nothing
Set olApp = Nothing
End Sub- Hide quoted text -


- Show quoted text -



  #6  
Old March 11th 08, 07:15 PM posted to microsoft.public.outlook.program_vba
JP[_3_]
external usenet poster
 
Posts: 201
Default Monthly E-Mails

Are you sending the same message each month, just to different
recipients?

--JP

On Mar 11, 12:53*pm, Gabe wrote:
Hmmm...Actually there are 10 seperate messages all with different recipients
that I send each month. Each procedure varies by month, for example: I send 5
messages in Jan, then I send 7 messages in Feb etc...Is there a way to
specify the message itself so that I can see which months each message is
being sent? Kinda like this,

If month(date) = 1,3,4,5,6,7,8,9,10,11,12 Then 'If the current date matches
any of these months, then send this message
With olMsg
* * .To = "
* * .Subject = "Monthly Report"
* * .Display
End With

If month(date) = 1,5,6,7,8,9,10,11,12 Then 'If the current date matches any
of these months, then send this message
With olMsg
* * .To = "
* * .Subject = "Monthly Report"
* * .Display
End With


  #7  
Old March 11th 08, 07:53 PM posted to microsoft.public.outlook.program_vba
Gabe
external usenet poster
 
Posts: 18
Default Monthly E-Mails

No different messages to different people each month.

Jan
Email1 - To: John, Joe, Jane
Email2 - To: Bob, Ben, Bill
Email3 - To: Mark, Mike, Max

Feb
Email1 - To: Sam, Sue, Sarah
Email2 - To: John, Joe, Jane
Eamil3 - To: Jake, Josh, John

"JP" wrote:

Are you sending the same message each month, just to different
recipients?

--JP

On Mar 11, 12:53 pm, Gabe wrote:
Hmmm...Actually there are 10 seperate messages all with different recipients
that I send each month. Each procedure varies by month, for example: I send 5
messages in Jan, then I send 7 messages in Feb etc...Is there a way to
specify the message itself so that I can see which months each message is
being sent? Kinda like this,

If month(date) = 1,3,4,5,6,7,8,9,10,11,12 Then 'If the current date matches
any of these months, then send this message
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With

If month(date) = 1,5,6,7,8,9,10,11,12 Then 'If the current date matches any
of these months, then send this message
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With



  #8  
Old March 12th 08, 12:16 AM posted to microsoft.public.outlook.program_vba
Gabe
external usenet poster
 
Posts: 18
Default Monthly E-Mails

I think I answered my own question, I just had to put in a case statement in.
Here is the final. Thanks again.

Sub MyFunction()
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Dim MyMonth
MyMonth = Month(Date) 'current month
Select Case MyMonth
Case 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12 'if the current month
(MyMonth) equals these months then send this message
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Attachments.Add ("C:\test.doc")
.Display
.BodyFormat = olFormatHTML
.HTMLBody = "HTMLHHello,/H2BODYBLOCKQUOTEAttached
is the monthly report./BLOCKQUOTE/BODY/HTMLHBODYThanks./HTML" &
..HTMLBody
End With
Set olMsg = Nothing
Set olApp = Nothing
End Select
Select Case MyMonth
Case 3, 4 'if the current month (MyMonth) equals these months then
send this message
Set olApp = Outlook.Application
Set olMsg = olApp.CreateItem(olMailItem)
With olMsg
.To = "
.Subject = "Monthly Report"
.Attachments.Add ("C:\test.doc")
.Display
.BodyFormat = olFormatHTML
.HTMLBody = "HTMLHHello,/H2BODYBLOCKQUOTEAttached
is the monthly report./BLOCKQUOTE/BODY/HTMLHBODYThanks./HTML" &
..HTMLBody
End With
Set olMsg = Nothing
Set olApp = Nothing
End Select
End Sub



"Gabe" wrote:

No different messages to different people each month.

Jan
Email1 - To: John, Joe, Jane
Email2 - To: Bob, Ben, Bill
Email3 - To: Mark, Mike, Max

Feb
Email1 - To: Sam, Sue, Sarah
Email2 - To: John, Joe, Jane
Eamil3 - To: Jake, Josh, John

"JP" wrote:

Are you sending the same message each month, just to different
recipients?

--JP

On Mar 11, 12:53 pm, Gabe wrote:
Hmmm...Actually there are 10 seperate messages all with different recipients
that I send each month. Each procedure varies by month, for example: I send 5
messages in Jan, then I send 7 messages in Feb etc...Is there a way to
specify the message itself so that I can see which months each message is
being sent? Kinda like this,

If month(date) = 1,3,4,5,6,7,8,9,10,11,12 Then 'If the current date matches
any of these months, then send this message
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With

If month(date) = 1,5,6,7,8,9,10,11,12 Then 'If the current date matches any
of these months, then send this message
With olMsg
.To = "
.Subject = "Monthly Report"
.Display
End With



  #9  
Old March 12th 08, 03:29 AM posted to microsoft.public.outlook.program_vba
JP[_3_]
external usenet poster
 
Posts: 201
Default Monthly E-Mails

Now you got it. Congrats!

--JP

On Mar 11, 7:16*pm, Gabe wrote:
I think I answered my own question, I just had to put in a case statement in.
Here is the final. Thanks again.

Sub MyFunction()
* * Dim olApp As Outlook.Application
* * Dim olMsg As Outlook.MailItem
* * Dim MyMonth
* * MyMonth = Month(Date) 'current month
* * Select Case MyMonth
* * * * Case 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12 'if the current month
(MyMonth) equals these months then send this message
* * * * * * Set olApp = Outlook.Application
* * * * * * Set olMsg = olApp.CreateItem(olMailItem)
* * * * * * * * With olMsg
* * * * * * * * .To = "
* * * * * * * * .Subject = "Monthly Report"
* * * * * * * * .Attachments.Add ("C:\test.doc")
* * * * * * * * .Display
* * * * * * * * .BodyFormat = olFormatHTML
* * * * * * * * .HTMLBody = "HTMLHHello,/H2BODYBLOCKQUOTEAttached
is the monthly report./BLOCKQUOTE/BODY/HTMLHBODYThanks./HTML" &
.HTMLBody
* * * * * * * * End With
* * * * * * Set olMsg = Nothing
* * * * * * Set olApp = Nothing
* * End Select
* * Select Case MyMonth
* * * * Case 3, 4 'if the current month (MyMonth) equals these months then
send this message
* * * * * * Set olApp = Outlook.Application
* * * * * * Set olMsg = olApp.CreateItem(olMailItem)
* * * * * * * * With olMsg
* * * * * * * * .To = "
* * * * * * * * .Subject = "Monthly Report"
* * * * * * * * .Attachments.Add ("C:\test.doc")
* * * * * * * * .Display
* * * * * * * * .BodyFormat = olFormatHTML
* * * * * * * * .HTMLBody = "HTMLHHello,/H2BODYBLOCKQUOTEAttached
is the monthly report./BLOCKQUOTE/BODY/HTMLHBODYThanks./HTML" &
.HTMLBody
* * * * * * * * End With
* * * * * * Set olMsg = Nothing
* * * * * * Set olApp = Nothing
* * End Select
End Sub

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calendar - Monthly alleycat Outlook - General Queries 1 September 25th 07 09:54 PM
monthly calendar alleycat Outlook - General Queries 0 September 24th 07 11:22 PM
monthly calendar alleycat Outlook - General Queries 0 September 24th 07 11:00 PM
monthly calendar alleycat Outlook - General Queries 1 September 24th 07 04:50 AM
Can's able to recieve mails but sending mails About Outlook Configuration Outlook - General Queries 4 July 5th 06 07:00 PM


All times are GMT +1. The time now is 07:36 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.