Jump to content

[Outlook] In a task, how can I style text as bold?


cag8f
 Share

Recommended Posts

Hi all.  I'm trying to use AutoIt to focus the description area of an already-open Outlook task, then activate bold text (screenshot).  With my code I can focus the description area, but when I then try to activate the 'Format Text' menu item, the description area loses focus, and the menu items all become disabled--I can't seem to click or activate the bold icon (screenshot).  Any ideas on what I'm doing wrong?  My code is below: 

#include <OutlookEX.au3>
Opt("SendKeyDelay", 10)     ;~ Wait 10 Ms between key strokes
Opt("WinTitleMatchMode", 2) ;~ Window Title Match Mode = Partial
WinActivate (" - Task")
ControlFocus(" - Task", "", "[CLASS:_WwG; INSTANCE:1]")
Send("!o"); Send text to the active window.

Thanks in advance.

Link to comment
Share on other sites

You could have a look at my OutlookEX UDF (for download please see my signature).
The following small example connects to the active item and sets the second and third word of the body to bold.

#include <OutlookEX.au3>

Global Const $wdCollapseStart = 1 ; Collapse the range to the starting point
Global Const $wdWord = 2 ; A word
Global Const $wdCharacter = 1 ; A character

Global $oOL = _OL_Open()
Global $oItem = $oOL.ActiveInspector
Global $oDoc = $oItem.WordEditor
Global $oRange = $oDoc.Range ; Get the range object
$oRange.Collapse($wdCollapseStart) ; Move the range start/end to the start of the document
$oRange.MoveStart($wdWord, 1) ; Move the range start/end to word 2
$oRange.MoveEnd($wdWord, 2) ; Move the range end two words to the right
$oRange.MoveEnd($wdCharacter, -1) ; Move the range end one character to the left (so the space isn't included)
$oRange.Font.Bold = True ; Set the font.underline property for the range

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I haven't played with your code and hence do not know what went wrong. But:

  • Don't automate the GUI when you can automate the API. GUI automation is error-prone as it might interfere with user activity (steal the focus so Send goes to the wrong window etc. etc.)
  • You do not check for errors after your function calls. Always make sure a function returned the desired result. If an error occurred inform the user and exit the script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...