Michal
05-18-2015, 10:07 AM
Hello Guys
I'm learning VBA to automate couple of things with my Outlook.
Now I'm trying to create a script that will generate email for me.
Unfortunately I'm stuck. 2nd code works perfect but 1st one returns type mismatch error. I tried to convert variables types but I failed,
Please advise
Thank you
Sub HelloWorldMessage()
Dim Msg As Outlook.MailItem
Set Msg = Application.CreateItem(olMailItem)
Msg.To = "[email address]"
Msg.Subject = "Todays All Green Today email" + DateAdd("m", 1, "31-Jan-95")
IntervalType = "d" ' "m" specifies months as interval.
FirstDate = Now()
Number = 1
SecondDate = DateAdd(IntervalType, Number, FirstDate)
Msg.Body = "New date: " & _
"Hello Team, [link]" + CStr(FirstDate) + "%20AND%20created%20%3C%3D%20" + CStr(SecondDate)
Msg.Display
Msg.Send
Set Msg = Nothing
End Sub
------------------------------------------------------------------------------------------
Sub Msg()
Dim FirstDate As Date ' Declare variables.
Dim IntervalType As String
Dim Number As Integer
Dim Msg
IntervalType = "d" ' "m" specifies months as interval.
FirstDate = Format(Now(), "yyyy-mm-dd")
Number = 1
SecondDate = DateAdd(IntervalType, Number, FirstDate)
Msg = "New date: " & _
"Hello Team, [link]" + CStr(FirstDate) + "%20AND%20created%20%3C%3D%20" + CStr(SecondDate)
MsgBox Msg
End Sub
I'm learning VBA to automate couple of things with my Outlook.
Now I'm trying to create a script that will generate email for me.
Unfortunately I'm stuck. 2nd code works perfect but 1st one returns type mismatch error. I tried to convert variables types but I failed,
Please advise
Thank you
Sub HelloWorldMessage()
Dim Msg As Outlook.MailItem
Set Msg = Application.CreateItem(olMailItem)
Msg.To = "[email address]"
Msg.Subject = "Todays All Green Today email" + DateAdd("m", 1, "31-Jan-95")
IntervalType = "d" ' "m" specifies months as interval.
FirstDate = Now()
Number = 1
SecondDate = DateAdd(IntervalType, Number, FirstDate)
Msg.Body = "New date: " & _
"Hello Team, [link]" + CStr(FirstDate) + "%20AND%20created%20%3C%3D%20" + CStr(SecondDate)
Msg.Display
Msg.Send
Set Msg = Nothing
End Sub
------------------------------------------------------------------------------------------
Sub Msg()
Dim FirstDate As Date ' Declare variables.
Dim IntervalType As String
Dim Number As Integer
Dim Msg
IntervalType = "d" ' "m" specifies months as interval.
FirstDate = Format(Now(), "yyyy-mm-dd")
Number = 1
SecondDate = DateAdd(IntervalType, Number, FirstDate)
Msg = "New date: " & _
"Hello Team, [link]" + CStr(FirstDate) + "%20AND%20created%20%3C%3D%20" + CStr(SecondDate)
MsgBox Msg
End Sub