Help with tasks in Outlook.ComObjActive("Outlook.Application")

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tazzzan33
Posts: 16
Joined: 07 Dec 2017, 12:41

Help with tasks in Outlook.ComObjActive("Outlook.Application")

22 Feb 2018, 13:57

I am trying to create a simple task via AHK. I have most of it working except I cannot set the time for the reminder. I would like the gui to select the data and time then feed it into a task and then save it. First I would like the time to be set then I can move on with the rest of the work. You can read more on the ReminderTime property here: https://msdn.microsoft.com/en-us/vba/ou ... ty-outlook

Code: Select all

Gui, Add, Text, x10 y15 w60 h20, StartDate:
Gui, Add, DateTime, x+10 y10 wp20 h20 vStartDate Section,

Gui, Add, Text, x10 y55 w70 h20 , StartTime:
Gui, Add, DateTime, x+10 y50 wp hp vStartTime 1, HH:mm:ss ;time

Gui, Add, Button, x10 y90 w60 h20 Default, &OK
Gui, Show, w200 h130, AHK-Scheduler

;Gui, Add, DateTime, vMyDateTime, LongDate
;Gui, Add, Button, default, OK
Gui, Show
return



ButtonOK:
;FormatTime, OutputVar,MyDateTime

Gui, Submit
Outlook := ComObjActive("Outlook.Application")
task := Outlook.Application.CreateItem(3)
tmp := task.ReminderTime
msgbox, %tmp%
;task.ReminderTime := StartDate+StartTime ;or something like that? 
task.ReminderSet := true
task.Display(true)
GUI, Destroy
ListVars
return
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Help with tasks in Outlook.ComObjActive("Outlook.Application")

23 Feb 2018, 00:00

tazzzan33 wrote:I am trying to create a simple task via AHK. I have most of it working except I cannot set the time for the reminder. I would like the gui to select the data and time then feed it into a task and then save it. First I would like the time to be set then I can move on with the rest of the work. You can read more on the ReminderTime property here: https://msdn.microsoft.com/en-us/vba/ou ... ty-outlook

Code: Select all

Gui, Add, Text, x10 y15 w60 h20, StartDate:
Gui, Add, DateTime, x+10 y10 wp20 h20 vStartDate Section,

Gui, Add, Text, x10 y55 w70 h20 , StartTime:
Gui, Add, DateTime, x+10 y50 wp hp vStartTime 1, HH:mm:ss ;time

Gui, Add, Button, x10 y90 w60 h20 Default, &OK
Gui, Show, w200 h130, AHK-Scheduler

;Gui, Add, DateTime, vMyDateTime, LongDate
;Gui, Add, Button, default, OK
Gui, Show
return



ButtonOK:
;FormatTime, OutputVar,MyDateTime

Gui, Submit
Outlook := ComObjActive("Outlook.Application")
task := Outlook.Application.CreateItem(3)
tmp := task.ReminderTime
msgbox, %tmp%
;task.ReminderTime := StartDate+StartTime ;or something like that? 
task.ReminderSet := true
task.Display(true)
GUI, Destroy
ListVars
return
Maybe this will help point you in the right direction:

Code: Select all

F12::
	olEmail := ComObjActive("Outlook.Application").ActiveWindow.CurrentItem	; Expects an Email to be open
	olEmail.MarkAsTask(2) ; olMarkThisWeek := 2
	olEmail.TaskDueDate := DatePlusDays(3)
	olEmail.FlagRequest := "Call " olEmail.SenderName
	olEmail.ReminderSet := true
	olEmail.ReminderTime  := DatePlusDays(2)
	olEmail.Save
return

Esc::ExitApp

DatePlusDays(Days, Format := "MM/dd/yyyy", Date := "")
{
	if !Date
		Date := A_Now
	Date += Days, Days
	FormatTime, Date, %Date%, %Format%
	return Date
}
The important thing is that ReminderTime is expecting a string in a specific format. Two strings containing a formatted date cannot simply be added together with something like StartDate+StartTime.

I am sure there are examples on the forum about how to do "date math" to add and subtract dates and times.

I believe ReminderTime is expecting something like this: 11/15/2010 10:00:00 AM

So it is important that you get your string looking like this.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Help with tasks in Outlook.ComObjActive("Outlook.Application")

23 Feb 2018, 21:03

FG, Would you mind explaining the line in your line of code above? I’ve seen similar references to this but I haven’t really understood what it does.

Code: Select all

Date += Days, Days
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Help with tasks in Outlook.ComObjActive("Outlook.Application")

24 Feb 2018, 00:12

kczx3 wrote:FG, Would you mind explaining the line in your line of code above? I’ve seen similar references to this but I haven’t really understood what it does.

Code: Select all

Date += Days, Days
Here is a link to docs:
https://autohotkey.com/docs/commands/EnvAdd.htm

It has the form of:
Var += Value , TimeUnits

In my code:
Date is a variable containing a date-time formatted string.
The first Days is a variable containing an integer like 2.
The second Days is a time unit, in this case Days.

So basically this is saying take the date in Date and add the amount in variable Days, as Days to Date.

The allowed time units to add are Seconds, Minutes, Hours, or Days.

You could also do something like:
X += Y, Hours
This would add Y hours to X.

Or TakeOffTime += 245, Seconds to add 245 seconds to TakeOffTime.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Help with tasks in Outlook.ComObjActive("Outlook.Application")

24 Feb 2018, 20:20

Cool thanks! I think that I’ve really only ever used EnvSub so haven’t had the use for the EnvAdd. Good to know

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 294 guests