UEZ

Excel / Outlook COM

42 posts in this topic

#1 ·  Posted (edited)

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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites



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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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!
¯\_(ツ)_/¯

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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!
¯\_(ツ)_/¯

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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!
¯\_(ツ)_/¯

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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!
¯\_(ツ)_/¯

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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!
¯\_(ツ)_/¯

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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!
¯\_(ツ)_/¯

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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!
¯\_(ツ)_/¯

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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!
¯\_(ツ)_/¯

Share this post


Link to post
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!
¯\_(ツ)_/¯

Share this post


Link to post
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

  • Similar Content

    • Rimoun
      By Rimoun
      Hello everyone
      I would like to have some help regarding my issue.
      I am trying to extract some information from excel sheet, I use _Excel_RangeFind then I get the array for the value then I check the array. In case the array is true the next will be to get some information based on the extracted array if no array because the value is not found it gives a messages box that the value is not found.
      My problem that the button works for one time only if i tried any value which exist in the sheet it gives me that value not found.
      I suspect that there is a problem regarding While loop.
      here is my code
      #include <GUIConstantsEx.au3> #include <WinAPI.au3> #Include <GuiListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> #include <ExcelConstants.au3> if FileExists ("result.txt") Then Sleep (100) Else readxl() EndIf Global $oExcel = _Excel_Open(False,False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Global $oWorkbook = _Excel_BookOpen($oExcel, "D:\info.xlsx",False,False) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel Error", "Error opening workbook '" & $oWorkbook & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf Local $lab1 = _Excel_RangeRead($oWorkbook, Default,"B1") Local $lab2 = _Excel_RangeRead($oWorkbook, Default,"C1") Local $lab3 = _Excel_RangeRead($oWorkbook, Default,"D1") Local $lab4 = _Excel_RangeRead($oWorkbook, Default,"E1") Global $sResult1,$sResult2,$sResult3,$sResult4,$sResult5,$sResult6 Global $asKeyWords = stringsplit (FileRead (@ScriptDir & "\result.txt"),@CRLF) Global Const $xlUp = -4162 ;~ _Main() Local $hGUI, $hList, $hInput, $aSelected, $sChosen, $hUP, $hDOWN, $hENTER, $hESC Local $sCurrInput = "", $aCurrSelected[2] = [-1, -1], $iCurrIndex = -1, $hListGUI = -1 $hGUI = GUICreate("Rimo System", 253, 270, 192, 124) Global $hInput = GUICtrlCreateInput("", 24, 48, 169, 21) Global $Label1 = GUICtrlCreateLabel("Rimo System", 80, 16, 150, 25) GUICtrlSetFont(-1, 14, 800, 0, "MS Serif") Global $Input2 = GUICtrlCreateInput("", 72, 144, 161, 21) Global $Input3 = GUICtrlCreateInput("", 72, 176, 161, 21) Global $Input4 = GUICtrlCreateInput("", 72, 208, 161, 21) Global $Input5 = GUICtrlCreateInput("", 72, 240, 161, 21) $Input6 = GUICtrlCreateInput("", 72, 272, 161, 21) $Input7 = GUICtrlCreateInput("", 72, 304, 161, 21) $Button1 = GUICtrlCreateButton("Get Info", 72, 88, 89, 33) $Label2 = GUICtrlCreateLabel("Label2", 16, 144, 36, 17) GUICtrlSetData( -1,$lab1) $Label3 = GUICtrlCreateLabel("Label3", 16, 176, 36, 17) GUICtrlSetData( -1,$lab2) $Label4 = GUICtrlCreateLabel("Label4", 16, 208, 36, 17) GUICtrlSetData( -1,$lab3) $Label5 = GUICtrlCreateLabel("Label5", 16, 240, 36, 17) GUICtrlSetData( -1,$lab4) $Label6 = GUICtrlCreateLabel("", 16, 272, 36, 17) $Label7 = GUICtrlCreateLabel("", 16, 304, 36, 17) $Button2 = GUICtrlCreateButton("Cancel", 112, 416, 121, 25) GUISetState(@SW_SHOW, $hGUI) Global $sSearch = guictrlread ($hInput) $hUP = GUICtrlCreateDummy() $hDOWN = GUICtrlCreateDummy() $hENTER = GUICtrlCreateDummy() $hESC = GUICtrlCreateDummy() Dim $AccelKeys[4][2] = [["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER], ["{ESC}", $hESC]] GUISetAccelerators($AccelKeys) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button2 Exit Case $Button1 Global $aResult = _Excel_RangeFind($oWorkbook, guictrlread($hInput) ,"A2:A2000") Global $aExtract = _ArrayExtract($aResult, 0, 0, 2, 2) if _elementExists($aExtract,0) Then getdata() Else MsgBox(0,"","Value Does Not Exist") EndIf Case $hESC If $hListGUI <> -1 Then ; List is visible. GUIDelete($hListGUI) $hListGUI = -1 Else ExitLoop EndIf Case $hUP If $hListGUI <> -1 Then ; List is visible. $iCurrIndex -= 1 If $iCurrIndex < 0 Then $iCurrIndex = 0 EndIf _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hDOWN If $hListGUI <> -1 Then ; List is visible. $iCurrIndex += 1 If $iCurrIndex > _GUICtrlListBox_GetCount($hList) - 1 Then $iCurrIndex = _GUICtrlListBox_GetCount($hList) - 1 EndIf _GUICtrlListBox_SetCurSel($hList, $iCurrIndex) EndIf Case $hENTER If $hListGUI <> -1 And $iCurrIndex <> -1 Then ; List is visible and a item is selected. $sChosen = _GUICtrlListBox_GetText($hList, $iCurrIndex) EndIf Case $hList $sChosen = GUICtrlRead($hList) EndSwitch Sleep(10) $aSelected = _GetSelectionPointers($hInput) If GUICtrlRead($hInput) <> $sCurrInput Or $aSelected[1] <> $aCurrSelected[1] Then ; Input content or pointer are changed. $sCurrInput = GUICtrlRead($hInput) $aCurrSelected = $aSelected ; Get pointers of the string to replace. $iCurrIndex = -1 If $hListGUI <> -1 Then ; List is visible. GUIDelete($hListGUI) $hListGUI = -1 EndIf $hList = _PopupSelector($hGUI, $hListGUI, _CheckInputText($sCurrInput, $aCurrSelected)) ; ByRef $hListGUI, $aCurrSelected. EndIf If $sChosen <> "" Then GUICtrlSendMsg($hInput, 0x00B1, $aCurrSelected[0], $aCurrSelected[1]) ; $EM_SETSEL. _InsertText($hInput, $sChosen) $sCurrInput = GUICtrlRead($hInput) GUIDelete($hListGUI) $hListGUI = -1 $sChosen = "" EndIf WEnd GUIDelete($hGUI) Func _CheckInputText($sCurrInput, ByRef $aSelected) Local $sPartialData = "" If (IsArray($aSelected)) And ($aSelected[0] <= $aSelected[1]) Then Local $aSplit = StringSplit(StringLeft($sCurrInput, $aSelected[0]), " ") $aSelected[0] -= StringLen($aSplit[$aSplit[0]]) If $aSplit[$aSplit[0]] <> "" Then For $A = 1 To $asKeyWords[0] If StringLeft($asKeyWords[$A], StringLen($aSplit[$aSplit[0]])) = $aSplit[$aSplit[0]] And $asKeyWords[$A] <> $aSplit[$aSplit[0]] Then $sPartialData &= $asKeyWords[$A] & "|" EndIf Next EndIf EndIf Return $sPartialData EndFunc ;==>_CheckInputText Func _PopupSelector($hMainGUI, ByRef $hListGUI, $sCurr_List) Local $hList = -1 If $sCurr_List = "" Then Return $hList EndIf $hListGUI = GUICreate("", 280, 160, 23, 62, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_MDICHILD), $hMainGUI) $hList = GUICtrlCreateList("", 0, 0, 170, 150, BitOR(0x00100000, 0x00200000)) GUICtrlSetData($hList, $sCurr_List) GUISetControlsVisible($hListGUI) ; To Make Control Visible And Window Invisible. GUISetState(@SW_SHOWNOACTIVATE, $hListGUI) Return $hList EndFunc ;==>_PopupSelector Func _InsertText(ByRef $hEdit, $sString) #cs Description: Insert A Text In A Control. Returns: Nothing #ce Local $aSelected = _GetSelectionPointers($hEdit) GUICtrlSetData($hEdit, StringLeft(GUICtrlRead($hEdit), $aSelected[0]) & $sString & StringTrimLeft(GUICtrlRead($hEdit), $aSelected[1])) Local $iCursorPlace = StringLen(StringLeft(GUICtrlRead($hEdit), $aSelected[0]) & $sString) GUICtrlSendMsg($hEdit, 0x00B1, $iCursorPlace, $iCursorPlace) ; $EM_SETSEL. EndFunc ;==>_InsertText Func _GetSelectionPointers($hEdit) Local $aReturn[2] = [0, 0] Local $aSelected = GUICtrlRecvMsg($hEdit, 0x00B0) ; $EM_GETSEL. If IsArray($aSelected) Then $aReturn[0] = $aSelected[0] $aReturn[1] = $aSelected[1] EndIf Return $aReturn EndFunc ;==>_GetSelectionPointers Func GUISetControlsVisible($hWnd) ; By Melba23. Local $aControlGetPos = 0, $hCreateRect = 0, $hRectRgn = _WinAPI_CreateRectRgn(0, 0, 0, 0) Local $iLastControlID = _WinAPI_GetDlgCtrlID(GUICtrlGetHandle(-1)) For $i = 3 To $iLastControlID $aControlGetPos = ControlGetPos($hWnd, '', $i) If IsArray($aControlGetPos) = 0 Then ContinueLoop $hCreateRect = _WinAPI_CreateRectRgn($aControlGetPos[0], $aControlGetPos[1], $aControlGetPos[0] + $aControlGetPos[2], $aControlGetPos[1] + $aControlGetPos[3]) _WinAPI_CombineRgn($hRectRgn, $hCreateRect, $hRectRgn, 2) _WinAPI_DeleteObject($hCreateRect) Next _WinAPI_SetWindowRgn($hWnd, $hRectRgn, True) _WinAPI_DeleteObject($hRectRgn) EndFunc Func _elementExists($array, $element) If $element > UBound($array)-1 Then Return False ; element is out of the array bounds Return True ; element is in array bounds EndFunc Func getdata() ;~ Local $sResult1 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","B")) ;~ Local $sResult2 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","C")) ;~ Local $sResult3 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","D")) ;~ Local $sResult4 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","E")) ;~ Local $sResult5 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","F")) ;~ Local $sResult6 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","G")) guictrlsetdata($Input2,$sResult1) guictrlsetdata($Input3,$sResult2) guictrlsetdata($Input4,$sResult3) guictrlsetdata($Input5,$sResult4) guictrlsetdata($Input6,$sResult5) guictrlsetdata($Input7,$sResult6) _Excel_Close($oExcel,Default,True) EndFunc Func readxl() Global $oExcel = _Excel_Open(False,False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Global $oWorkbook = _Excel_BookOpen($oExcel, "D:\info.xlsx",False,False) LOcal Const $xlUp = -4162 With $oWorkbook.ActiveSheet ; process active sheet $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) ; get a Range that contains the last used cells $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count ; get the the row count for the range starting in row/column 1 and ending at the last used row/column $iLastCell = .Cells($iRowCount + 1, "B").End($xlUp).Row ProgressOn("Copying Cells", "Copying Cells progress", "0%") For $i = 2 to $iLastCell Local $total = Int(($i/$iLastCell)*100) Local $sResult3 = _Excel_RangeRead($oWorkbook, Default, "A" & $i) FileWriteLine("result.txt",$sResult3) ProgressSet(($i/$iLastCell)*100, $total & "%") Next ;~ FileWrite("result.txt",$sResult3) ProgressSet(100, "Done", "Complete") Sleep (1500) ProgressOff() _Excel_Close($oExcel,Default,True) EndWith EndFunc  
    • robertocm
      By robertocm
      change linked image paths in excel 2007 Open XML Files with AutoIt and 7-zip:
      #include <File.au3> ;Change this Local $sFind = "C:\Users\MyUserName\Documents\MyImageFolder\My%20Image1.png" Local $sReplace = "C:\Users\ANOTHERUSERNAME\Documents\AnotherImageFolder\My%20Image1.png" Local Const $sMessage = "Directory to change excel image paths" Local $sFileSelectFolder = FileSelectFolder($sMessage, "") Local $sTempDir = @ScriptDir & "\testdir" ;Required 7-zip Local $PathZipProgram = @ProgramFilesDir & "\7-Zip\" If Not(FileExists($PathZipProgram & "\7z.exe")) Then MsgBox(16, "", "7z.exe not found in path " & $PathZipProgram) Exit EndIf ;look for excel files in selected directory and all subdirectories Local $SFileList = _FileListToArrayRec($sFileSelectFolder, "*.xls.;*.xlsm", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) If Not @error Then For $i = 1 To $SFileList[0] DirRemove($sTempDir, 1) ;use x command to keep the folder stucture, -aoa Overwrite All existing files without prompt, use -r to unzip the subfolders from the zip file RunWait('"' & $PathZipProgram & '7z.exe" x -aoa -r "' & $SFileList[$i] & '" -o"' & $sTempDir & '" -y', $PathZipProgram, @SW_HIDE) __ReplaceImagePaths($sTempDir, $sFind, $sReplace) RunWait('"' & $PathZipProgram & '7z.exe" a -r "' & $SFileList[$i] & '" "' & $sTempDir & '\*" -tzip -y', $PathZipProgram, @SW_HIDE) Next Else MsgBox(16, "Error", "No files were found in the folder specified.") EndIf DirRemove($sTempDir, 1) Func __ReplaceImagePaths($sTempDir, $sFind, $sReplace) ;List all files with .xml.rels extension in the directory \xl\drawings\_rels Local $aFileList = _FileListToArray($sTempDir & "\xl\drawings\_rels", "*.xml.rels", 1, True) If @error = 1 Then ;MsgBox (0, "", "Path was invalid") SplashTextOn("Title", "Path was invalid", -1, -1, -1, -1, 1, "", 24) Sleep(2000) SplashOff() Exit EndIf If @error = 4 Then ;MsgBox (0, "No files", "No files were found") SplashTextOn("Title", "No files were found", -1, -1, -1, -1, 1, "", 24) Sleep(2000) SplashOff() Exit EndIf Local $iRetval ;Loop through the array For $i = 1 To $aFileList[0] $iRetval = _ReplaceStringInFile($aFileList[$i], $sFind, $sReplace) Next EndFunc  
      Some references:
      https://stackoverflow.com/questions/37145369/change-path-to-picture-links-in-excel http://www.jkp-ads.com/Articles/Excel2007FileFormat.asp
    • TheDcoder
      By TheDcoder
      Hello
      I am relatively new to the world of Microsoft Office and the Excel UDF.
      I am trying to loop through every row in a spreadsheet and get the text/values from each column in the given row... so far I have looked into the Help file for the Excel UDF and the wiki page for Excel UDF but I have no idea about how this is done ... This is all I have in my script:
      Global $oExcel = _Excel_Open(False, False, False, False, True) Global Const $sSpreadsheet = @ScriptDir & '\data.xlsx' Global $oSpreadsheet = _Excel_BookOpen($oExcel, $sSpreadsheet, True, False) ; ... I am placing my bet on the _Excel_Range functions... especially _Excel_RangeRead. I don't know how $vRange works so I would be glad if someone can point me in the right direction . What I would ideally like is to get all of the contents of the spreadsheet (it's just a normal text one) in a 2D array.
      Thanks in Advance!
    • VeryGut
      By VeryGut
      So, I have stumbled upon a problem with countring rows in excel files.
      The script I am working on will count the total number of rows of every file in the folder it was placed into.
      It is to my understanding that UsedRange counts rows even if they are empty, provided that a user has previously edited them. In other words, even if the file has two rows, the script might return 1000, if I edit and then leave empty cell (A,1000). How can I avoid this happening?
      Thanks in advance!
       
      #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <Excel.au3> Global $Files = _FileListToArray (@ScriptDir, "*") $oExcel = _Excel_Open() $TotalNumberOfRows = 0 for $i=2 to $Files[0] Sleep(1000) $sWorkbook = @ScriptDir & "\" & $Files[$i] Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook) Sleep(2000) $NumberOfRows = $oExcel.ActiveSheet.UsedRange.Rows.Count $TotalNumberOfRows= $TotalNumberOfRows + $NumberOfRows MsgBox(1, "", "Number of invoices: " & $TotalNumberOfRows) Sleep(100) _Excel_BookClose ($oWorkbook, False) Next  
    • SkysLastChance
      By SkysLastChance
      Is there an easy way to format a cell to date or currency? I found some old threads that were not much help. 
      I have looked at the wiki but I only see how to format as a number
      I assume there is not a way like I did for making the text bold. 
      Any suggest or help would be appreciated. 
       
       
      I am able to get the format changed to text using
      $oExcel.Activesheet.range("A1:L1").NumberFormat = "@"  
      #include <Excel.au3> Global $sBox Func InputHowMany() While 1 $sBox = Number(InputBox("How many?", "How many?")) If $sBox = 0 Then $iMsg = MsgBox(1, 'Oops', 'Please enter a valid number') If $iMsg = 2 Then Exit Else Return $sBox - 1 EndIf WEnd EndFunc InputHowMany() $oExcel = _Excel_Open() $oExcel = _Excel_BookNew($oExcel) Local $t = 2 Local $w = 1 Local $c = 301 $oExcel.Activesheet.range("A1:L1").font.bold = True Do _Excel_RangeWrite($oExcel,Default, "Status", "A1") _Excel_RangeWrite($oExcel,Default, "Last Name", "B1") _Excel_RangeWrite($oExcel,Default, "Last Name", "C1") _Excel_RangeWrite($oExcel,Default, "SSN", "D1") _Excel_RangeWrite($oExcel,Default, "DOB", "E1") _Excel_RangeWrite($oExcel,Default, "Email", "F1") _Excel_RangeWrite($oExcel,Default, "Mailing Address", "G1") _Excel_RangeWrite($oExcel,Default, "City", "H1") _Excel_RangeWrite($oExcel,Default, "State", "I1") _Excel_RangeWrite($oExcel,Default, "Zip Code", "J1") _Excel_RangeWrite($oExcel,Default, "Gender", "K1") _Excel_RangeWrite($oExcel,Default, "Phone", "L1") _Excel_RangeWrite($oExcel,Default, '=B' & $c, "B" & $t) _Excel_RangeWrite($oExcel,Default, '=C' & $c, "C" & $t) _Excel_RangeWrite($oExcel,Default, '=D' & $c, "D" & $t) _Excel_RangeWrite($oExcel,Default, '=E' & $c, "E" & $t) _Excel_RangeWrite($oExcel,Default, '=F' & $c, "F" & $t) _Excel_RangeWrite($oExcel,Default, '=G' & $c, "G" & $t) _Excel_RangeWrite($oExcel,Default, '=H' & $c, "H" & $t) _Excel_RangeWrite($oExcel,Default, '=I' & $c, "I" & $t) _Excel_RangeWrite($oExcel,Default, '=J' & $c, "J" & $t) _Excel_RangeWrite($oExcel,Default, '=K' & $c, "K" & $t) _Excel_RangeWrite($oExcel,Default, '=L' & $c, "L" & $t) $c = $c + 1 $t = $t + 1 $w = $w + 1 Until $w > $sBox