Jump to content

Excel / Outlook COM


UEZ
 Share

Recommended Posts

Is there a way to avoid that the hidden Excel window will be shown when another instance is opened / attached externally?

Example:

#include <Excel.au3>
#include "..\Office\Outlook\OutlookEX.au3" ;adjust this path!

Global $hGUI = GUICreate("Test")
GUISetState()

Global $aField9[2] = [9, $xlTextFormat]
Global $aFieldInfo[1] = [$aField9]
Global $oWorkbook = Null, $oExcel = _Excel_Open(False, False, True, False, True), $oOutlook = _OL_Open()
Global $sWorkbook = @ScriptDir & "\Test.txt", $sExcel = @ScriptDir & "\Test.xlsx"
$oWorkbook = _Excel_BookOpenText($oExcel, $sWorkbook, 2, $xlDelimited, Default, True, ",", $aFieldInfo, ".", Default, Default, 65001)

$iRows = $oWorkbook.ActiveSheet.UsedRange.Rows.Count - 1
$iColumns = $oWorkbook.ActiveSheet.UsedRange.Columns.Count - 1


$oOutlook_Mail = $oOutlook.CreateItem(0)
With $oOutlook_Mail
    .To = ""
    .CC = ""
    .BCC = ""
    .Subject = "Test"
    .Attachments.Add($sExcel, 1, 1)
    .Display
EndWith

Do
Until GUIGetMsg() = -3

_OL_Close($oOutlook)
_Excel_Close($oExcel, False, True)

 

When I start the script it will load the comma separated text file hidden in the background, open a new Outlook window and attach an Excel file.

Now, when I double click the attachment in the Outlook window to open the attachment also the hidden Excel window is shown.

How can I avoid that the hidden window is shown?

 

I'm using Office 2013.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • Replies 41
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Can't you close Excel before displaying the mail item?

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

No, the text file opened by Excel is needed to display data according to the selection made by the user.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Maybe

$oExcel.Windows($oWorkbook.Name).Visible = False

after _Excel_BookOpenText does the trick? This is executed when $bVisible is set to False for function _Excel_BookOpen.

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

That's not working because the Excel functions after this trick will not work anymore

Getting an em

A COM error as been triggered
Number is: 80010105
Scriptline is: 292
WinDescription is: The server threw an exception

 

If I'm inserting the line just before the $oOutlook_Mail = $oOutlook.CreateItem(0) then the hidden Excel window will be shown but the content is not visible.

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

How many Excel instances are running after the user opened the Excel attachment from the Outlook mail?

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

In this case I'm the user. ;)

 

At the beginning no Excel instances are running.

After starting the script only one instance caused by $oExcel = _Excel_Open(False, False, True, False, True).

Still one instance after text file load

When clicking on the attachment still one Excel instance but two Excel windows are visible now.

 

Excel will be opened with the /dde parameter.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

   Excel will be opened with the /dde parameter.

Can you please describe what that means?

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

Another question:
Why does the user need to double click the attachment? Can't you just open the original file?

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

Can you please describe what that means?

When I look in the registry how Excel.exe is opened then I see the /dde parameter. I just want to mention it.

 

Another question:
Why does the user need to double click the attachment? Can't you just open the original file?

Don't ask why a user needs to double click on the attachment. Probably because it is there or just want to check the content before sending it.

 

Some more background information. My scripts takes a huge comma separated text file, loads it using Excel, makes several sorting and filtering to display the data.

The user has the option to save the generated output as an Excel file or mail with the attachment.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I'm sure it's me but I still don't get why you can't close Excel after having done all the processing and before creating the mail.
When the user decides to open the attachment then Excel is started again.

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'm sure it's me but I still don't get why you can't close Excel after having done all the processing and before creating the mail.
When the user decides to open the attachment then Excel is started again.

Because the hidden Excel holds the data which is used to display the information. The Excel table holds all the rack information for all the coordinates. The user selects the coordinate and my tool displays the rack with all devices.

Neither I cannot show the code nor some data which is not needed to show my problem. Sorry.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I just tried your example script with AutoIt 3.3.12.0 and Office 2010 on Windos 7 32 bit.
I get two Excel icons in the task bar but can not switch to the hidden worksheet (test.txt).

 

 

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

This code removes one of the two Excel icons but you now no longer can switch to Excel using alt+tab.

#include <Excel.au3>
#include <OutlookEX.au3>

Global $hGUI = GUICreate("Test")
GUISetState()

Global $aField9[2] = [9, $xlTextFormat]
Global $aFieldInfo[1] = [$aField9]
Global $oWorkbook = Null, $oExcel = _Excel_Open(False, False, True, False, True), $oOutlook = _OL_Open()
Global $sWorkbook = @ScriptDir & "\Test.txt", $sExcel = @ScriptDir & "\Test.xlsx"
$oWorkbook = _Excel_BookOpenText($oExcel, $sWorkbook, 2, $xlDelimited, Default, True, ",", $aFieldInfo, ".", Default, Default, 65001)

$iRows = $oWorkbook.ActiveSheet.UsedRange.Rows.Count - 1
$iColumns = $oWorkbook.ActiveSheet.UsedRange.Columns.Count - 1


$oOutlook_Mail = $oOutlook.CreateItem(0)
With $oOutlook_Mail
    ;   .To = ""
    .CC = ""
    .BCC = ""
    .Subject = "Test"
    .Attachments.Add($sExcel, 1, 1)
    .Display
EndWith
$oExcel.Windows($oWorkbook.Name).Visible = False
Do
Until GUIGetMsg() = -3

_OL_Close($oOutlook)
_Excel_Close($oExcel, False, True)

 

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

Thanks water but the invisible Excel window which will be visible isn't control able anymore until script is closed.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I think this is caused by the way you call _Excel_Open and set parameter $bInteractive to False.
Try to set this parameter to True.

Global $oWorkbook = Null, $oExcel = _Excel_Open(False, False, True, True, True), $oOutlook = _OL_Open()

 

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

Now the Excel windows is control able but also close able which is fatal for the script.

The best solution would be that the Excel instance which will be created as invisible stays invisible. All other solutions are not 100% safe.

 

Thanks.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

The workbook created by _Excel_BookOpenText stays invisible here (I'm running Office 2010).
I use the following stripped down script:

#include <Excel.au3>
#include <OutlookEX.au3>

GUICreate("Test")
GUISetState()

; Excel part
Global $aField9[2] = [9, $xlTextFormat]
Global $aFieldInfo[1] = [$aField9]
Global $sWorkbook = @ScriptDir & "\Test.txt"
Global $sExcel = @ScriptDir & "\Test.xlsx"
Global $oExcel = _Excel_Open(False, False, True, True, True)
Global $oWorkbook = _Excel_BookOpenText($oExcel, $sWorkbook, 2, $xlDelimited, Default, True, ",", $aFieldInfo, ".", Default, Default, 65001)
; Create Outlook mail
Global $oOutlook = _OL_Open()
$oOutlook_Mail = $oOutlook.CreateItem(0)
With $oOutlook_Mail
    ;   .To = ""
    .CC = ""
    .BCC = ""
    .Subject = "Test"
    .Attachments.Add($sExcel, 1, 1)
    .Display
EndWith
$oExcel.Windows($oWorkbook.Name).Visible = False
Do
Until GUIGetMsg() = -3
_OL_Close($oOutlook)
_Excel_Close($oExcel, False, True)

So with Office 2013 Excel still displays test.txt and test.xlsx when the user opens the mail attachment?

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

This seems to work for this snippet of code but not for the complete app. I need to check why...

Thanks.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

It is somehow possible to check whether the Outlook window was closed / Send button was pressed?

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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

×
×
  • Create New...