Search the Community

Showing results for tags 'excel'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • General
    • Announcements and Site News
    • Chat
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office


  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office


  • Forum
  • AutoIt


  • Community Calendar

Found 173 results

  1. I'm trying to insert the following formula in cell A2 using my script: =if(A1=""; "YES"; "NO") To my understanding, the line of code should be similar to this: _Excel_RangeWrite($MasterFile, Default, "=if(A1=""; "YES"; "NO")", "A2") However, it does not work, probably due to the multiple quotation marks that confuse the script :C How do I avoid this problem?
  2. Hi everybody, i have a question about Excel, i have to create several charts one below the other dynamically. I have thought to use: $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count And then to use it in this way: $Graph_position = "=Test1!A"&$iRowCount+2&":K"&$iRowCount+24 But it doesn't work with charts. Does anyone have a suggestion?
  3. Hi all, i have an empty csv file, i have a non formatted text file. What do i want to do? I want to automate the process "get external data" in Excel, i want to import the data from the text file and basically create a csv file with a specific character encoding. Is it possible with AutoIT?
  4. I want to create a excel file from my script if it does not exist. _ExcelBookOpen throws error=2 if file does not exist, after this error i want to create new file at this point. can i use _FileCreate()? _Logger($sLogPath, "{INFO}------: Opening Excel File: " & $sExcelPath& "") While 1 Local $oExcelTestResult = _ExcelBookOpen($sExcelPath) If @error = 2 Then If not _FileCreate($sResExcelPath) Then MsgBox(0, "Error", "Error In Opening REsult Excel File: Error: " & String(@error)) _Logger($sLogPath, "{ERROR}------: Result Excel File does not exist.. tried to create new but :ERROR : " & String(@error) & "") ExitLoop Else _Logger($sLogPath, "{INFO}------: Result Excel File does not exist.. **Created New**: ") EndIf Else ExitLoop EndIf WEnd
  5. How to avoid save violation error in excel?
  6. Hi everybody, i have to store an entire row of a Excel workbook into an array. The row index is stored in a variable. How can i do it? Thanks in advance for your support.
  7. Hi I have an issue with _ExcelRangeFind, i have a it working on another PC but on my pc i just gives me this error "d:\AutoIt3\Include\Excel.au3" (656) : ==> The requested action with this object has failed.: $aResult[$iIndex][1] = $oMatch.Name.Name $aResult[$iIndex][1] = $oMatch^ ERROR I have trimmed the script to the absolute minimum. What iy should do, I give it a number, It opens an excel file, and then it reads through coloumn A and then returns an array when it finds the number in Excel. The number is in coloumn A of the Excel sheet. The versions of autoit are the same on both machines. The Excel sheet opens correctly, but it crashes on the rangefind command. I have also tried this $NavisionIDFound = _Excel_RangeFind($Movielistsheet,$NavisionID,"A1:A10000",Default,$xlWhole,True), with the same result. #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <GuiButton.au3> #include <GuiComboBox.au3> #include <Excel.au3> ;Includes from source dir #include <_RecFileListToArray.au3> #include <_XMLDomWrapper.au3> $MovielistExcel = "h:\Movie list.xlsm" LoadDataFromMovieListSheet() Func LoadDataFromMovieListSheet() ConsoleWrite("Load Data From MovieList Sheet" & @LF) $NavisionID = 106266 ; Create application object $ExcelAppHandle = _Excel_Open(Default,Default,Default,Default,True) If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $Movielistsheet = _Excel_BookOpen($ExcelAppHandle, $MovielistExcel, True, Default) ;~ Read the formulas of a cell range (all used cells in column A) $NavisionIDFound = _Excel_RangeFind($Movielistsheet,$NavisionID,$Movielistsheet.ActiveSheet.Usedrange.Columns("A:A"),Default,$xlWhole,True)
  8. Hi everybody, i have to write a value into an excel column. I know where it starts from, but i don't know what the end is, last non-empty cell. How can i get the number of last non-empty cell? Thanks in advance. Regards
  9. Hi All, I have excel file like this and i want to cut cell/text from excel to other software. I have to cut the cell of B column one by one and past into other software If Winexists("No Data Found") then restore cuted cell and goto next/down side cell How to do it ?
  10. I am not sure why I am getting the this error on my second pass of the code. 1 - $oWorkbook is not an object or not a workbook object Any help or advice on my code appreciated. #include <Excel.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") Global $vRow = 2 If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,"Untitled","A2",3) $oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92",Default,$xlWhole) $Clip = _ArrayToClip($oFind,"",0,0,"",2,2) Send("{ScrollLock Off}") $hWnd = WinWait("[CLASS:XLMAIN]") ControlSend($hWnd, "", "", ("^g")) WinWait("[CLASS:bosa_sdm_XL9]") ; Go To ControlSend($hWnd, "", "", ("^v")) ControlSend($hWnd, "", "", ("{Enter}")) ControlSend($hWnD, "", "", "{Down " & $vRow & "}") Do $oTime = _Excel_RangeRead ($oExcel2,"Untitled","B2",3) If @error Then Exit MsgBox(0, "Error", "Error" & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox(0,"Test",$oTime) IF $oTime = "7:10:00 AM" Then $oCalls1 = _Excel_RangeRead ($oExcel2,Default,"C" & $vRow,3) $oCalls2 = _Excel_RangeRead ($oExcel2,Default,"D" & $vRow,3) ControlSend($hWnd, "", "", $oCalls1) ControlSend($hWnd, "", "", ("{RIGHT}")) ControlSend($hWnd, "", "", $oCalls2) $vRow = $vRow + 1 ContinueLoop Else $vRow = $vRow + 1 EndIf Until $vRow = 4 1.xlsm 2.xlsx
  11. Hey Community, cause im too new in the Auto it world i will try it with the your help. hopefully. I woud like to know how i can handle my Problem. ---- I have a Excel Data with 362 random numbers. For Example: 1166642335374 1172899897343 ..... this numbers are a part of the filepath ...example D:\Projekte\1166_64233_5374 as u can see its the first number of the Excel data. After the first 4 numbers it shoud make a "_" than another 5 "_" This is my first question. How can i handle this to make it Shell execute. -------- Second question: If i am in the path. For Example: D:\Projekte\1166_64233_5374 the code shoud search for specific PDF Files. They are named like: 0050569E364B1ED79B900F73E62660EC.pdf the first 15 letters are always the same 0050569E364B1ED when he found this data he has to copy it on a Folder on the Desktop. (There can also be 2 or 3 pdfs in one Folder with this letters) ---- Please give me some help :-)
  12. My Main goal is to copy the info from sheet 2 and put it in the correct date and time location on sheet 1. 1.xlsm - Password 2007 2.xlsx 1. I do not understand why I am unable to find the date. I am reading the value and searching for the value. But, it never turns anything up. 2. What would be the best way (function) to go about selecting the second cell underneath the date after I have found it? So Ideally, I would want to match the date. Once it finds the date go 2 cells down insert the data from sheet 2. I believe I have a good idea on how to loop the script. The only thing I am not sure on is how to take the cell I find and get the cell location (exp. A2) to go the cell that I find and select 2 cells down and go to A4. In other words I don't know how to put the cell I find into a variable that I can use to position where I start to input data. Any help is appreciated as always. #include <Excel.au3> #include <Array.au3> MsgBox(0, "", "Open Excel 1") Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") MsgBox(0, "", "Open Excel 2") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,Default,"A2") $oRead1 = _Excel_RangeRead($oExcel1,Default,"BY4") MsgBox (0,"Test",$oRead) MsgBox (0,"Test",$oRead1) $oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD4") If @error Then MsgBox(4096, "", "No File(s) chosen") Else Local $aSalesResult = _Excel_RangeFind($oExcel1, $oRead, Default, Default, $xlWhole) _Arraydisplay($aSalesResult, "RangeFind", 2, 0, "", "|", "Col|Sheet|Name|Cell|Value|Formula|Comment") EndIf
  13. I get this error, Whenever I try to find a date. Does anyone have any idea why? I saw some post from 2015, However I would imagine this is fixed by now. @water >"J:\Temporary Files\XXXXXXXXX\AutoIt\AutoIt\AutoIt\SciTe\..\autoit3.exe" /ErrorStdOut "C:\Users\XXXXXX\Desktop\Call Report Automation.au3"     "J:\Temporary Files\XXXXXXXX\AutoIt\AutoIt\AutoIt\Include\Excel.au3" (656) : ==> The requested action with this object has failed.: $aResult[$iIndex][1] = $oMatch.Name.Name $aResult[$iIndex][1] = $oMatch^ ERROR >Exit code: 1    Time: 5.791 #include <Excel.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,Default,"A2",3) _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7") Sleep (1000) _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92") MsgBox (0,"Test",$oRead) UPDATE: If I take out this line it works. By works I mean I don't get the error. :/ However, I need it. I am just confused. _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7") UPDATE 2: I also get this error when trying to use the helpfile examples. I have version \AutoIt\AutoIt\AutoIt\Include\Excel.au3" (670) : ==> The requested action with this object has failed.: $oSheet = $oWorkbook.Sheets($iIndexSheets) $oSheet = $oWorkbook^ ERROR >Exit code: 1 Time: 0.8931
  14. Hi, Wondering what I'm doing wrong. as per my script, I activate an external program, copy data from it and I want to paste it into excel, after I clear the current sheet that is there. It is some sort of an array as when I manually paste it into excel it expands across rows and down columns (number of which varies). This repeats for Xno. of program instances, and consequently I would want it to cycle through x sheets. So far I have the following, noting that I dont have the sheet clearing thing detailed yet, but I get the following error: "Error copying cells. @error = 4, @extended = -2147352567" func Primary() For $i=0 to ubound($term)-1 WinActivate($term[$i]) sleep(500) MouseClick("left",$OptX,$opty) Clipput("") sleep(500) send("!a") sleep(100) Do sleep(100) until Clipget() ;activates sheet no. specified by $i+ 1, removes data from sheet and pastes new data, cycles to the next sheet ;function to clear sheet _Excel_RangeCopyPaste($oWorkbook1.Worksheets($i+1), Default , "A1") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example 2", "Error copying cells." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example 2", "Range 'A1' from workbook _Excel3.xls successfully copied to 'G15'.") Next EndFunc Any help would be great.
  15. ExcelChart



    Extensive library to control and manipulate Microsoft Excel charts. Theads: General Help & Support - Example Scripts BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort KNOWN BUGS (last changed: 2017-07-21) None. The COM error handling related bugs have been fixed.
  16. Hello everyone , I have spotted a weird problem with the Excel COM API. It doesn't read a spreadsheet with a good amount of lines in a cell... Enough talk, let's get into code: #include <Array.au3> #include <Excel.au3> Global $oExcel = _Excel_Open(False, False, False, False, True) Global Const $sSpreadsheet = @ScriptDir & '\Test.xlsx' Global $oSpreadsheet = _Excel_BookOpen($oExcel, $sSpreadsheet, True, False) Global $aSpreadsheet = _Excel_RangeRead($oSpreadsheet) If @error Then MsgBox(0, "Error", 'Error Code: ' & @error & @CRLF & 'Extended Code: ' & @extended) _Excel_Close($oExcel, False) _ArrayDisplay($aSpreadsheet) (Download Test.xlsx) I get this error when I run the script: If you open the spreadsheet, you can see that I have dummy text in the B2 cell. If you replace the contents of the cell B2 with something like Test4, it will work perfectly fine: Is this some kind of undocumented line limit for Excel? Thanks in Advance! TD
  17. Hi guys, I was trying to automate a webpage after getting input from excel. The script worked fine for like 5 iterations but then stopped all of a sudden, I dont have the exact error msg now, but it was pointing to this in the IE UDF:- Return SetError($_IESTATUS_Success, $oTemp.GetElementsByTagName($sTagName).length, When i looked up the forum there was a similar question which said that I have to fix KB 3008923 update by uninstalling it, but I am unable to do that. here is the link for download:- ( i guess ) Does anybody know the proper steps to solve this?? Plus I wont be able to send the code here because of privacy policy n all by the company. Desperately looking for a reply.....
  18. 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
  19. 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:
  20. 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!
  21. hello guys, I'm doing one excel pivot connected to a mysql script to display it in a table array . I need you to open the excel file , the pivot is updated . where do I fix it?
  22. 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
  23. 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
  24. I have an issue with disk space on a server so I wrote a simple little script to check specific directories and save the sizes to an Excel spreadsheet. For this script, I am still using version Everything works fine, I just have a question. #cs ---------------------------------------------------------------------------- AutoIt Version: #ce ---------------------------------------------------------------------------- #include<date.au3> #include<excel.au3> #include<array.au3> $file = FileOpen(@ScriptDir & "\CMScriptDirList.txt", 0) If @error Then Exit ;--folder view still OK $oexcel = _ExcelBookOpen(@ScriptDir & "\CMScriptDirSizesCopy.xlsx") If @error Then Exit ;--folder view now parent folder $excelArray = _ExcelReadSheetToArray($oexcel) $lastrow = $excelArray[0][0] $lastcol = $excelArray[0][1] _ExcelWriteCell($oexcel, _NowCalc(), 1, $lastcol + 1) While 1 $line = FileReadLine($file) If @error Then ExitLoop $size = DirGetSize(StringStripWS($line, 3)) / 1024 / 1024 $iIndex = _ArraySearch($excelArray, $line, 0, 0, 0, 0, 1, 1) If @error Then ContinueLoop _ExcelWriteCell($oexcel, $size, $iIndex, $lastcol + 1) WEnd FileClose($file) _ExcelWriteFormula($oexcel, "=SUM(R2C" & $lastcol + 1 & ":R38C" & $lastcol + 1 & ")", 39, $lastcol + 1) _ExcelWriteFormula($oexcel, "=R39C" & $lastcol + 1 & "/1024", 40, $lastcol + 1) $oexcel.ActiveSheet.columns($lastcol).copy ;used to copy the format of the original last column of the spreadsheet $oexcel.ActiveSheet.columns($lastcol + 1).PasteSpecial(-4122, Default, Default, Default) ;this just pastes the format of the original last column to the new last column $oexcel.ActiveSheet.Range("A1").Select ;select cell A1 just to unselect the entire column from previous command $oexcel.columns.AutoFit ;auto sizes the column width _ExcelBookClose($oexcel, 1) ;save file when closing The script is compiled and sitting is a sub-directory on the server in question. The text file and the spreadsheet that are used are both in this same folder as well. When I navigate to the folder and run the script by double-clicking on the executable, the process runs but the folder view where I ran the script will go back up one level so when the script completes, I am in the parent folder from where I started. I have added message boxes throughout the script and have determined that the folder view goes back up one level at some point after the @error check for the file open and before the @error check for the ExcelBookOpen (where the comments are). I just wanted to know if someone can tell me why and if there is a way to prevent it. (Note: still using v3.3.8.1 on this machine but slowly converting scripts to v3.3.14.2).
  25. I am a newbie in AutoIt. May I know what is the code used to expand the width and height of excel cells because I want to insert pictures in the cell.I tried AutoFit but that doesnt work as I cant specify for the width and height. Only for column width I could expand by using .ColumnWidth but for the row I am not able to expand the row? How to do?? What is the code used ??Please help me and thank you.