Jump to content
LoneWolf_2106

Error calculating the last row in excel

Recommended Posts

LoneWolf_2106

Hi,

i have an error:

==> The requested action with this object has failed.:
$iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count
$iRowCount = .Range(^ ERROR

 

My code is:

$oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell)
Sleep(1000)
$iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count
Sleep(1000)
_Excel_RangeWrite($oWorkbook_1, $oWorkbook_1.ActiveSheet,$aFileList[$i][2] , "AB3:AB"&$iRowCount)

I have added some sleep because the application was crashing more often before, so i thought to slow down the code execution.

But i didn't solve the issue.

Has anyone an idea of what the problem might be?

Thanks in advance.

Share this post


Link to post
Share on other sites
water

Can you please post the full code? Dot notation only works in a With block. 

Edited by water

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
LoneWolf_2106
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <Excel.au3>
#include <WinAPIShellEx.au3>
#include <Excel_Funktion_test.au3>

; Script Start 

Local Const $sMessage = "Select a folder"

    ; Display an open dialog to select a file.
Global $sFileSelectFolder = FileSelectFolder($sMessage, "")
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.")
    Else
        ; Display the selected folder.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder)
    EndIf

Global $Cloud_Folder=""

FolderWrite()
Sleep(1000)

Global $aFileList = _FileListToArray($sFileSelectFolder, Default, Default, True)

$Output_Index = _ArraySearch($aFileList, "Output_Cloud",0,0,0,1)


_ArrayDelete($aFileList, $Output_Index)

FolderScan()

$Path_Len = StringLen($sFileSelectFolder)
_ArrayColInsert($aFileList, 1)



For $i=1 To UBound($aFileList) - 1
    $aFileList[$i][1] = StringTrimLeft($aFileList[$i][0], $Path_Len+1)
Next



_ArrayColInsert($aFileList, 2)


For $i = 1 To UBound($aFileList) - 1

    $split_array=StringSplit($aFileList[$i][1], "_", 2 )

    $aFileList[$i][2] = $split_array[0]
Next






For $i=1 To UBound($aFileList) - 1
    $Excel_File_1 = $aFileList[$i][0]
    Local $oExcel_1 = _Excel_Open()
    Local $vZeile_2 =""
    If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $sWorkbook_1 = $Excel_File_1
    Local $oWorkbook_1 = _Excel_BookOpen($oExcel_1, $sWorkbook_1)
    Sleep(1000)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook_1 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;   MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Workbook '" & $sWorkbook_1 & "' has been opened successfully." & @CRLF & @CRLF & "Creation Date: " & $oWorkbook_1.BuiltinDocumentProperties("Creation Date").Value)
    With $oWorkbook_1.ActiveSheet ; process active sheet

        $vZeile_2=_Excel_RangeRead($oWorkbook_1, Default, "A2")

        $vRange=$oWorkBook_1.Activesheet.Range("A2").EntireRow

        If $vZeile_2 = "" Then
            _Excel_RangeDelete($oWorkbook_1.ActiveSheet, $vRange, $xlShiftUp, 1)
        EndIf

        Sleep(1000)

        $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell)
        Sleep(1000)
        $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count
        Sleep(1000)
        _Excel_RangeWrite($oWorkbook_1, $oWorkbook_1.ActiveSheet,$aFileList[$i][2] , "AB3:AB"&$iRowCount)
    EndWith
    ;_Excel_RangeWrite($oWorkbook_1, $oWorkbook_1.ActiveSheet,$aFileList[$i][2] , "AB3:AB"&$iRowCount)
    Sleep(1000)
    _Excel_BookSaveAs($oWorkbook_1, $Cloud_Folder&"\"&$aFileList[$i][1], $xlWorkbookDefault, true)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Error saving workbook to '" & $sWorkbook_1 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Workbook successfully saved as '" & $sWorkbook_1 & "'.")
ShellExecute($sWorkbook_1)
Sleep(1000)
_Excel_Close($oExcel_1,False, True)
if @error then MsgBox($MB_OK, "error", @error)
ProcessClose("EXCEL.exe")
Sleep(1000)
Next

Sleep(1000)



Global $aFileList_Modified = _FileListToArray($Cloud_Folder, Default, Default, True)

;_ArrayDisplay($aFileList_Modified)


For $j=1 To UBound($aFileList_Modified) - 1

    ;MsgBox($MB_OK, "test", $aFileList_Modified[$j])

    SpalteAA($aFileList_Modified[$j])
    if @error then MsgBox($MB_OK, "error", @error)
    Sleep(1000)
    ProcessClose("EXCEL.exe")
    Sleep(1000)
Next

MsgBox($MB_OK, "Info", "Alle Dateien wurden bearbeitet")


Func FileSearch()

  ; Assign a Local variable the search handle of all files in the current directory.
    Local $hSearch = FileFindFirstFile("XYZ.xlsx")

    ; Check if the search was successful, if not display a message and return False.
    If $hSearch = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.")
        Exit
    Else

        Return True
    EndIf

    ; Close the search handle.
    FileClose($hSearch)
EndFunc

Func FolderScan()
    ; List all the files and folders in the desktop directory using the default parameters and return the full path.
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Exit
    EndIf
    ; Display the results returned by _FileListToArray.
    ;_ArrayDisplay($aFileList, "$aFileList")
EndFunc

Func FolderWrite()

$Cloud_Folder=$sFileSelectFolder&"\Output_Cloud"

$Folder_exists=FileExists($Cloud_Folder)

If $Folder_exists=0 Then

    _WinAPI_ShellCreateDirectory ( $Cloud_Folder)

EndIf

EndFunc

I hope that this is enough :) If you need also the second part(which has no influence on the main one), let me know.

Thanks in advance for your support.

Share this post


Link to post
Share on other sites
water

Will check on Friday as I‘m on vacation right now. 

  • Like 1

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
LoneWolf_2106

Enjoy your vacation :-)

Edited by LoneWolf_2106

Share this post


Link to post
Share on other sites
LoneWolf_2106

I have noticed that the issue occurs only with the 32 bit Version. The issue is not reproducible in the 64 bit Version.

I have 64 bit OS and Excel is 32 bit.

Share this post


Link to post
Share on other sites
water

I noticed you use your own Excel include file. 
Do you still get the error when using the default Excel UDF that comes with AutoIt?


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
Faalamva

Hi,

This code will give you the last row of column 1, and the last column on row 1 of your Excel file :

$MaxRow = $oWorkbook.Sheets($SheetName).Range("A99999").End(-4162).Row
$MaxCol = $oWorkbook.Sheets($SheetName).Range("ZZ1").End(-4159).Column

-4162 is the internal Excel code for "XlUp" and -4159 the one for "XlToLeft".

Make sure to adapt the 99999 and ZZ if necessary (i.e. if not high enough).

Share this post


Link to post
Share on other sites
JLogan3o13

@LoneWolf_2106 when you say last row I am assuming you mean last used row, correct? If so, there are a couple of ways you can do it.

   Something like this is you want all of the data in an array, for later manipulation:

#include <Array.au3>
#include <Excel.au3>

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @DesktopDir & "\defects.xlsx")
Local $aRange = _Excel_RangeRead($oWorkbook, Default, $oExcel.ActiveSheet.UsedRange)

_Excel_BookClose($oWorkbook)
_Excel_Close($oExcel)

    $iLastRow = (UBound($aRange))
    ConsoleWrite($iLastRow & @CRLF)

   Or something like this is you purely want to know the row count:

#include <Array.au3>
#include <Excel.au3>

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @DesktopDir & "\defects.xlsx")
Local $iLastRow = $oExcel.ActiveSheet.UsedRange.Rows.Count

_Excel_BookClose($oWorkbook)
_Excel_Close($oExcel)

    ConsoleWrite($iLastRow & @CRLF)

 

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Juvigy
On 11/16/2017 at 1:56 PM, LoneWolf_2106 said:

I have noticed that the issue occurs only with the 32 bit Version. The issue is not reproducible in the 64 bit Version.

I have 64 bit OS and Excel is 32 bit.

I think the issue comes from here. Why dont you compile a 32bit script and then a 64bit and test it?

Share this post


Link to post
Share on other sites
LoneWolf_2106

@Juvigy I have compiled 2 Versions, i have tested both for 3 hours. The 32 bit one crashes sometimes.

I would like just to find out the reason, in order to avoid the same issue in the future.

Share this post


Link to post
Share on other sites
water

You have to compile the AutoIt script for the bitness of Excel.
Means:
If Excel is 32 bit then you need to compile your AutoIt script for 32 bit.
If Excel is 64 bit then you need to compile your AutoIt script for 64 bit.


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
water

You open the Excel application over and over again in your Loop. I have cleaned up your loop a bit:

Local $vZeile_2, $sWorkbook_1, $oWorkbook_1
Local $oExcel_1 = _Excel_Open()
If @error Then Exit MsgBox(16, "My Script", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
For $i = 1 To UBound($aFileList) - 1
    $Excel_File_1 = $aFileList[$i][0]
    $vZeile_2 = ""
    $sWorkbook_1 = $Excel_File_1
    $oWorkbook_1 = _Excel_BookOpen($oExcel_1, $sWorkbook_1)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook_1 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    With $oWorkbook_1.ActiveSheet ; process active sheet
        $vZeile_2 = _Excel_RangeRead($oWorkbook_1, Default, "A2")
        $vRange = $oWorkbook_1.Activesheet.Range("A2").EntireRow
        If $vZeile_2 = "" Then _Excel_RangeDelete($oWorkbook_1.ActiveSheet, $vRange, $xlShiftUp, 1)
        $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell)
        $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count
        _Excel_RangeWrite($oWorkbook_1, $oWorkbook_1.ActiveSheet, $aFileList[$i][2], "AB3:AB" & $iRowCount)
    EndWith
    _Excel_BookSaveAs($oWorkbook_1, $Cloud_Folder & "\" & $aFileList[$i][1], $xlWorkbookDefault, True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "My Script", "Error saving workbook to '" & $Cloud_Folder & "\" & $aFileList[$i][1] & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; ShellExecute($sWorkbook_1)
Next
_Excel_Close($oExcel_1, False, True)
If @error Then MsgBox($MB_OK, "error", @error)

 

Edited by water

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
water

Another question:
What is

ShellExecute($sWorkbook_1)

for?


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
LoneWolf_2106

@water, thanks for your support. Please ignore that line, i have removed it from the code, i don't even remember what test i have made in August :-)

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

    • MrCheese
      By MrCheese
      Hi guys,
      without including everything (unless you want it)
      I am copying data from a table in chrome and wanting to paste it into excel.
      Copying in Chrome works.
      I can paste it into the field i want by emulating goto -> ctrl V:
      WinActivate($dataload) WinWaitActive($dataload) Sleep(500) $oWorkbook1.Sheets("ItemReturn").Activate Sleep(500) $msg = "Measuring Sheet" conwrite() ttips2() Local Const $xlUp = -4162 With $oWorkbook1.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, "B")).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 ; start in the row following the last used row and move up to the first used cell in column "B" and grab this row number EndWith $NewStartCell = $iLastCell + 2 $msg = "moving to location" conwrite() ttips2() Sleep(250) Send("^g") WinWait("Go To") Sleep(100) Send("B" & $NewStartCell) Sleep(100) Send("{ENTER}") Sleep(500) Send("^v")  
      But, I want to use _excel_rangecopypaste, pasting from the clipboard
      _Excel_RangeCopyPaste($oWorkbook1.ActiveSheet, default, "B" & $NewStartCell,default,$xlPasteValuesAndNumberFormats) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example 2", "Error pasting cells." & @CRLF & "@error = " & @error & ", @extended = " & @extended) however, this gives me error 4 , extended@:  -2147352567
      How can i fix this or find out how to debug this error?
       
      Thanks
    • Simpel
      By Simpel
      Hi.
      I try to figure out who is using a excel workbook which I can only open "read only". I use this code:
      #include <Array.au3> #include <Excel.au3> Local $sFile = ; excel file with path on a network drive Local $oExcel = _Excel_Open(True, True) Local $oTabelle = _Excel_BookOpen($oExcel, $sFile) Local $aUsers If IsObj($oTabelle) Then $aUsers = $oTabelle.UserStatus _ArrayDisplay($aUsers) EndIf If I am the one allowed to write to the excel file (I'm the first one who opened it) then I will get an array with myself:

      If my collegue opened the excel file first and I run the code I get the following error message:
      "H:\_Conrad lokal\Downloads\AutoIt3\_COX\Tests\test.au3" (9) : ==> The requested action with this object has failed.: $aUsers = $oTabelle.UserStatus $aUsers = $oTabelle^ ERROR The excel file is on a network drive. Is that's the problem?
      Regards, Conrad
    • 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 EDITED:
      Note: it seems that if User Account Control (UAC) is enabled then 7zip is unable to overwrite the destination file (using the same name).
      In this case, a possible solution would be to rename the original excel file before (see _PathSplit in help file).
      In my case i prefer just to disable UAC
    • SOF-TECH
      By SOF-TECH
      Dear all,
      Can someone show  me how to en hance the below function to write in CSV  into column  and rows the input values ? 
      I am getting this result: 

      I would like the result to be as this 

      From A1:C1 is for headers
      From A2:C2 is for input Data
      Global Const $GUI_EVENT_CLOSE = -3 $sDataFilePath = @ScriptDir & "\Records.csv" #region ### START Koda GUI section ### Form= $Form1 = GUICreate("Demo1: New Record", 580, 115) $Input1 = GUICtrlCreateInput("", 10, 30, 270, 21) $Input2 = GUICtrlCreateInput("", 300, 30, 270, 21) $Input3 = GUICtrlCreateInput("", 10, 80, 270, 21) $Label1 = GUICtrlCreateLabel("Name:", 10, 10, 35, 17) $Label2 = GUICtrlCreateLabel("ID:", 300, 10, 18, 17) $Label3 = GUICtrlCreateLabel("Phone No:", 10, 60, 55, 17) $Button1 = GUICtrlCreateButton("Save to CSV", 450, 70, 120, 30) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _ExportData() MsgBox(64, @ScriptName, "Record Saved.") EndSwitch WEnd Func _ExportData() If Not FileExists($sDataFilePath) Then FileWriteLine($sDataFilePath, "Name;ID;Phone No.;") EndIf For $i = $Input1 To $Input3 FileWrite($sDataFilePath, GUICtrlRead($i) & ";") Next FileWriteLine($sDataFilePath, "") EndFunc ;==>_ExportData May be Excel UDF has be to be added but I can manage that my self  
      Thank you in advance
    • MrCheese
      By MrCheese
      HI there
      this is driving me nuts - i get the row count, but not the column count - what am I missing? Thanks for your help!
      #include <Excel.au3> #include <Array.au3> #include <MsgBoxConstants.au3> ; XlDirection enumeration: https://msdn.microsoft.com/en-us/library/office/ff820880.aspxGlobal $oExcel = _Excel_Open() Global $xlup = -4162 Global $xlByRows, $xlPrevious, $xlByColumns Global $oExcel = _Excel_Open() $bookname = "temp.xlsx" $sWorkbook = @ScriptDir & "\" & $bookname Global $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook, Default, Default, True) 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 $iColCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Column.Count MsgBox(0, "", "row:" & $iRowCount & "Col:" & $iColCount) EndWith  
      for context - i want to :
      * count columns used in excel
      * create ini file from the rows in each column - finishing at the last column used - i.e. one column for one ini file; containing 15 rows or so.
      is it better to read the entire sheet to an array via the sheettoarray function? then read it from that?
       
       
      temp.xlsx
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.