Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Mickers Outlook COM MSDN for Ahk_L


  • Please log in to reply
35 replies to this topic
Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012
An user asked how to create a new message keeping the default signature.

I searched around and found about GetInspector object. That page has an example in VBA that I have translated to AHK and as suggested by ruespe I'm sharing my solution here as well. :)

; Example of creating a message keeping the default signature
olMailItem := 0
MailItem := ComObjActive("Outlook.Application").CreateItem(olMailItem)
myInspector := MailItem.GetInspector
wdDoc := myInspector.WordEditor
wdRange := wdDoc.Range(0, wdDoc.Characters.Count)
wdRange.InsertBefore("This is the body.")
MailItem.Display

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


Person93
  • Members
  • 443 posts
  • Last active: Feb 11 2014 12:07 AM
  • Joined: 26 Jan 2012

Is there a way to copy the selected item from the active Explorer window to an MSG file?

 

Or is there a way to paste the object in the clipboard into a MSG file?



Person93
  • Members
  • 443 posts
  • Last active: Feb 11 2014 12:07 AM
  • Joined: 26 Jan 2012

Bump.



Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012

Is there a way to copy the selected item from the active Explorer window to an MSG file?
 
Or is there a way to paste the object in the clipboard into a MSG file?


; Save selected items as .msg files

Path = %A_MyDocuments%\Email\ ; Make sure you set an existing folder for the output.

^+s::
Ol := ComObjActive("Outlook.Application")
Selection := Ol.ActiveExplorer().Selection
Loop, % Selection.Count
{
	ThisItem := Selection.Item(A_Index)
	Date := RegExReplace(ThisItem.ReceivedTime, "\W")
	Subject := ThisItem.Subject
	ThisItem.SaveAs(Path Date " " Subject ".msg", olMSG := 3)
}
return

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


cappo
  • Members
  • 6 posts
  • Last active: Dec 05 2013 01:12 AM
  • Joined: 22 Jan 2012

I have found this post really helpful to convert my hybrid ahk and outlook vba scripts into something totally ahk.  I've been stuck on one problem for a few days now using mailitem.move  The relevant code is below.   

ol := ComObjActive("Outlook.Application") 
objNS = ol.GetNamespace("MAPI")
objNS := objNS.Folders.Item("Personal CJC").Folders.Item("Deleted Items")
vMailItem := vMailItem.Move(objNS)

I keep getting  Error:  0x80020005 - Type mismatch no matter what i do with quotes, brackets, spaces etc.  Im lost!!

 

Any help would be greatly appreciated.



Joe Glines
  • Members
  • 118 posts
  • Last active: Jan 24 2016 03:08 PM
  • Joined: 23 Dec 2009

I wrote this a while back (I had a heck of a time figuring it out as well)

#SingleInstance, Force ; Only allow one version running
Browser_Back:: ; Launch test Hotkey
mail :=    ComObjActive("Outlook.Application").GetNameSpace("MAPI").GetDefaultFolder[6] ; Access the Session NameSpace
myDestFolder := mail.Folders("Personal Mail")
numb := mail.Items.Count
;MsgBox % numb

Loop %  mail.Items.Count
{
   ;  if   Instr(mail.Items[A_Index].SenderName,"JoeTazz") { ;just an example how to use sender name
     if   Instr(mail.Items[A_Index].Subject,"commented on") {
      Item := mail.Items(A_Index)
My .= A_Index ","
   }
}

StringTrimRight, My, My, 1 ; remove final `n
Sort, My , N, R, D, ; Numeric sort
; MsgBox % My

Loop, parse, My, `,
   mail.Items[A_LoopField].Move(myDestFolder)
return

It moves any item in my Inbox that has "commented on" in the subject line to a folder beneath the inbox entitled "Personal Mail"


Automating the mundane 1 script at a time...
https://www.linkedin.com/in/joeglines
The-Automator

cappo
  • Members
  • 6 posts
  • Last active: Dec 05 2013 01:12 AM
  • Joined: 22 Jan 2012

Thanks joetazz.  Using the inbox as the starting folder in your method worked.  Thanks for that.  it doesnt solve my dilema yet because my folders are variables and not always starting at the inbox but at least i know it is the folder definition now and not something I am doing wrong elsewhere.

 

I'll let you know when i solve it.



cappo
  • Members
  • 6 posts
  • Last active: Dec 05 2013 01:12 AM
  • Joined: 22 Jan 2012
An update - I'm not sure why it is the case but when you create the folder path one tree level at a time it seems to work.  
 

Thanks for getting me back on the right track joetazz

olns:=ol.GetNamespace("MAPI")
myFolder1:=olns.folders("Mailbox")
myFolder2:=myFolder1.folders("Inbox")
myFolder3:=myFolder2.folders("aaa")


vMailItem.Move(myFolder3)


JovanniB
  • Members
  • 25 posts
  • Last active: Aug 21 2015 02:06 PM
  • Joined: 31 Jul 2013

Hi,

 

great work, huge effort to document all that stuff.

 

What Im still searching is a possibility to call a VBA-Macro (VBA-Code) in OL2010 external by AHK via Outlook COM

 

Does somebody know how that could work ? please let me know.

 

J.M.

 

 



bobc119
  • Members
  • 10 posts
  • Last active: Feb 24 2014 11:17 AM
  • Joined: 29 Jun 2013

Cappo, you probably are not looking for this anymore, but for anyone else:

 

your issue is probably that you're calling the Item property, which doesn't exist for the Folders object:

 

objNS := objNS.Folders.Item("Personal CJC").Folders.Item("Deleted Items")

If you just added an "s" to the end of "Item", it would have probably have worked. The Folder Object has an "Items" property but not an "Item" property:

objNS := objNS.Folders.Items("Personal CJC").Folders.Items("Deleted Items")

I think its actually clearer to skip the Items part:

objNS := objNS.Folders("Personal CJC").Folders("Deleted Items")

This will return a folder object, representing the Deleted Items folder

 

 

@JovanniB: It doesn't seem possible, since there is no Run method in Outlook.



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Can anyone help me iterate through the AddIns collection?

I can get Obj.COMAddIns.Count to return the expected number, but I cannot get Addin Objects using obj.COMAddIns(x)

 

eg I want to get the name of all the AddIns, as per here:

https://msdn.microso...office.11).aspx



kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

COMAddIn Object

olApp := ComObjActive("Outlook.Application")
for COMAddIn, in olApp.COMAddIns
  MsgBox, % COMAddIn.Creator "`n" 
    . COMAddIn.Description "`n"
    . COMAddIn.Guid "`n"
    . COMAddIn.ProgId

or

Loop, % olApp.COMAddIns.Count
{
  COMAddIn := olApp.COMAddIns.Item[A_Index]
  MsgBox, % COMAddIn.Creator "`n" 
    . COMAddIn.Description "`n"
    . COMAddIn.Guid "`n"
    . COMAddIn.ProgId
}


evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Excellent, thank you!



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Does anyone know how to automate the "From" field in an outlook message?

 

To clarify, I mean this From field:

11188.jpg

 

Cheers



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
If your using COM to automat outlook you may be able to use ".SentOnBehalfOfName" insted of ".from"
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About