Jump to content

Open Outlook Custom Form (OFT) and read


Recommended Posts

I'm totally newbie with Autoit and still trying to learn how Autoit can help me to automate some of my work.

Here is what I'm trying to do:

- The oft files is always on desktop, only 1 oft files with random names

- Display Outlook custom form (OFT) (Outlook Form Template) in Outlook 2007

- Read data in the form (Name, Address, etc)

- Paste the data in other program specific text box (Name, Address, etc)

What I achieve so far:

- Assign Hotkey to execute the command

- Check if the outlook already open, and active

- Open the oft

Here some of my progress:

#Include <HotKey.au3>
Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F1 = 0x70

; Assign "F1" switch to Open OFT in outlook
_HotKeyAssign($VK_F1, 'OpenOFT')
Func OpenOFT()
 IF WinExists("Microsoft Outlook") Then
 IF NOT WinActive("Microsoft Outlook") Then
 WinActivate("Microsoft Outlook")
            send ("{ALT}fno{DOWN 7}{Enter}")
        else
            send ("{ALT}fno{DOWN 7}{Enter}")
        EndIf
    Else
    MsgBox(0, "", "No Outlook Program Opened!")
 EndIf
EndFunc

; Assign "CTRL-ESC" with Quit()
_HotKeyAssign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit')
While 1
    Sleep(10)
WEnd

Func Quit()
    Exit
EndFunc ;==>Quit

After searching the internet, I found more reliable way to open the OFT using VBA:

Sub MakeItem()
Set newItem = Application.CreateItemFromTemplate("c:\your path\open test.oft")
newItem.Display
Set newItem = Nothing
End Sub

But I don't know how to convert this to Autoit and how to read the OFT data.

- Should I send {TAB} to get to the input box and send ^c ?

- Send command to save the data in notepad and calling it back to paste in my other program by lines?

Any help would be appreciate.

Link to comment
Share on other sites

Please have a look at the Outlook UDF. There you'll see how to access Outlook elements.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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 already see that, in fact I already search outlook and see all the 40 page result for 3 days.

All the code are more toward mail and not custom form.

So it's kinda give me problem to use it in my script.

Need a better example to navigate and copy in Custom Form as well as converting the Open OFT VBA script.

Link to comment
Share on other sites

The mentioned UDF gives you a lot of examples on how to access Outlook using the COM interface.

If your VBA code works then it should be easy to convert it to AutoIt:

$oOutlook = ObjCreate("Outlook.Application")
$oNewItem = $oOutlook.CreateItemFromTemplate("c:\your path\open test.oft")
$oNewItem.Display

More information can be found here.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

#Include <HotKey.au3>
Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F1 = 0x70

; Assign "F1" switch to Outlook
_HotKeyAssign($VK_F1, 'win1')
Func win1()
    IF WinExists("Outlook Today - Microsoft Outlook") Then
        IF NOT WinActive("Outlook Today - Microsoft Outlook") Then
        WinActivate("Outlook Today - Microsoft Outlook")
            $oOutlook = ObjCreate("Outlook.Application")
            $oNewItem = $oOutlook.CreateItemFromTemplate("c:\test.oft")
            $oNewItem.Display
        else
            $oOutlook = ObjCreate("Outlook.Application")
            $oNewItem = $oOutlook.CreateItemFromTemplate("c:\test.oft")
            $oNewItem.Display
        EndIf
    Else
    MsgBox(0, "", "No Outlook program Opened!")
    EndIf
EndFunc

; Assign "CTRL-ESC" with Quit()
_HotKeyAssign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit')
While 1
    Sleep(10)
WEnd

Func Quit()
    Exit
EndFunc   ;==>Quit

Thank you so much! It work!

Now I need to study how to access them using COM.

Link to comment
Share on other sites

From your first post I suspect you open a contact item. If this is true then the valid methods and properties can be found here.

To display the "fullname" property of the contact you will need something like:

$sFullName = $oNewItem.FullName
msgbox(0,"","Full Name: " & $sFullName)
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Your code had working only for normal properties such as cc, subject, to

How I want to retieve data from custom properties? such as Textbox1?

I try with this code but cannot capture the data.

$sSolution = $oNewItem.UserProperties("TextBox17")
msgbox(0,"","Solution: " & $sSolution
Link to comment
Share on other sites

I think it should read:

$sSolution = $oNewItem.UserProperties("TextBox17").Value
msgbox(0,"","Solution: " & $sSolution)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Not working :blink:

Keep getting Error: Object reference outside a "With" statement.

Edited: Yeah! Its working!!!! my mistake is wrong properties name xD Thanks you very much!

Can give me some idea how to code this?

Ex1: CU-0JP208-21833-943-01W8 and the output just "JP208" (take only the fifth number to number 8 and removing others - of course the number of the serial is random but will have same format just like this)

Ex2: #I love you water# and the output would be just "I love you water" without the # (actually I want to remove leading and trailing space) (It look like StringStripWS can do the trick)

Edited by myteam
Link to comment
Share on other sites

Can give me some idea how to code this?

Ex1: CU-0JP208-21833-943-01W8 and the output just "JP208" (take only the fifth number to number 8 and removing others - of course the number of the serial is random but will have same format just like this)

If the string is always in the format ab-ABCDEF-12345-... and you always need BCDEF then you can use
$Result = StringMid($property,5,5)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Haven't done much with IE and AutoIt but have a look at the IE UDF (it's part of standard AutoIt).

_IEFormElementSetValue and _IEFormSubmit should get you started.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

$oIE = _IEAttach ("Link Contact")
$oIEContactPerson = _IEGetObjByName($oIE, "LASTNAME1")
$oIEClearDistPhone1 = _IEGetObjByName($oIE, "PHONE")
$oIEClearDistPhone2 = _IEGetObjByName($oIE, "HOME_PHONE")
$oIEClearDistEmail = _IEGetObjByName($oIE, "EMAIL")
_IEFormElementSetValue($oIEContactPerson, $sClearDistContactPerson)
_IEFormElementSetValue($oIEClearDistPhone1, $sClearDistPhone1)
_IEFormElementSetValue($oIEClearDistPhone2, $sClearDistPhone2)
_IEFormElementSetValue($oIEClearDistEmail, $sClearDistEmail)

It Work!!! Really! Thank You again for advice me !!!

One more question,

Can give me some idea how to code this?

ex: water@google.com;myteam@yahoo.com

I just want the output just take the first mail "water@google.com", of course the number of character can be increase depend on the email name.

Link to comment
Share on other sites

To split strings at a specific character please use function StringSplit. It returns an array. So:

$aMail = StringSplit("water@google.com;myteam@yahoo.com",";")

will return an array like:

$aMail[0] = 2

$aMail[1] = water@google.com

$aMail[2] = myteam@yahoo.com

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Thanks for the idea. :blink:

Another help needed,

I have no problem to read address in the form that have textbox.

However, sometimes the form use label (caption) to show the address.

The problem is:

- cannot highlight the label (cannot copy)

- The data is in property: caption.

- There is no value to point to. (label don't have property name)

How can I read the label?

I try with

$sDistAddress1 = $oNewItem.Label28.caption

But get an error since the OFT form is read only.

Just to make thing clear, I want to read this data from the label (Circled)

Posted ImagePosted Image

Edited by myteam
Link to comment
Share on other sites

I fear I can't help you with that.

I'm no Outlook guru and never before have worked with OFTs. Even Google didn't help me.

Sorry :blink:

One last question: What error message do you get? Could you post a hardcopy?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Error: The requested action with this object has failed.

I ready hope someone can help me read the label in outlook.

Search in google usually return result about changing label instead of reading it...

I try with this code also get same error

$sDistDistAddress1 = $oNewItem.Controls.items("Label28")
Link to comment
Share on other sites

Can you post an example OFT so I can do some testing?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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 think I got it :blink:

Use

$sLabelCaption = $oNewItem.GetInspector.ModifiedFormPages("Message").Controls("Label28").caption
ConsoleWrite($sLabelCaption & @CRLF)

to get the labels caption.

I got the hint from here - part 6.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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...