Jump to content
senatin

Cant Opening excel Book2.xlsx

Recommended Posts

senatin

I cant figure out how to make it work so far I got this code

#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>
#include <Excel.au3>

HotKeySet( "{ESC}", "out")

$Form1 = GUICreate("Senatin V.3.7.9", 466, 422, 79, 132)
$hRichEdit = _GUICtrlRichEdit_Create($Form1, "", 12, 161, 241, 249, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))

Local $xlup = -4162

Local $oExcel = _Excel_Open()
If @error Then
    ConsoleWrite("Cant open Excel" & @CRLF)
    Exit
EndIf

Local $oWorkbook = _Excel_BookOpenEX($oExcel, @ScriptDir & "Book2.xlsx", True)
If @error Then
    ConsoleWrite("Cant open book " & @error & @CRLF)
    _Excel_Close($oExcel)
    Exit
EndIf

Local $iRow = $oWorkbook.ActiveSheet.Range("A65536").End($xlup).Row
InsertText( $iRow, 8, "-bo", 0x000000)

GUISetState(@SW_SHOW)



While 1
    Sleep(100)
WEnd


Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iIncrement = 0, $sAttrib = "", $iColor = -1)

    ; Count the @CRLFs
    StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "")
    Local $iLines = @extended
    ; Adjust the text char count to account for the @CRLFs
    Local $iEndPoint = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines
    ; Add new text
    _GUICtrlRichEdit_AppendText($hWnd, $sText & @CRLF)
    ; Select text between old and new end points
    _GuiCtrlRichEdit_SetSel($hWnd, $iEndPoint, -1)
    ; Convert colour from RGB to BGR
    $iColor = Hex($iColor, 6)
    $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2)
    ; Set colour
    If $iColor <> -1 Then _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor)
    ; Set size
    If $iIncrement <> 0 Then _GUICtrlRichEdit_ChangeFontSize($hWnd, $iIncrement)
    ; Set weight
    If $sAttrib <> "" Then _GUICtrlRichEdit_SetCharAttributes($hWnd, $sAttrib)
    ; Clear selection
    _GUICtrlRichEdit_Deselect($hWnd)

EndFunc

Func InsertText($text, $size, $bold, $clor)

   Static Local $Lasttxt = ""
   Static Local $Lastsize = 0

   If $text <> $Lasttxt then
      $Lastsize = $size - $Lastsize
      _GUICtrlRichEdit_WriteLine($hRichEdit, $text , $Lastsize, $bold, $clor)
      $Lasttxt = $text
      $Lastsize = $size
   Endif


EndFunc

Func _Excel_BookOpenEX($oExcel, $sFilePath, $bReadOnly = Default, $bVisible = Default, $sPassword = Default, $sWritePassword = Default, $bUpdateLinks = Default)
    ; Error handler, automatic cleanup at end of function
    Local $oError = ObjEvent("AutoIt.Error", "__Excel_COMErrFunc")
    #forceref $oError
    If Not IsObj($oExcel) Or ObjName($oExcel, 1) <> "_Application" Then Return SetError(1, @error, 0)
    If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)
    If $bReadOnly = Default Then $bReadOnly = False
    If $bVisible = Default Then $bVisible = True
    Local $oWorkbook = $oExcel.Workbooks.Open($sFilePath, $bUpdateLinks, $bReadOnly, Default, $sPassword, $sWritePassword)
    If @error Then Return SetError(3, @error, 0)
    Local $oWindow = $oExcel.Windows($oWorkbook.Name) ; <== Modified
    If IsObj($oWindow) Then $oWindow.Visible = $bVisible ; <== Modified
    ; If a read-write workbook was opened read-only then set @extended = 1
    If $bReadOnly = False And $oWorkbook.Readonly = True Then Return SetError(0, 1, $oWorkbook)
    Return $oWorkbook
EndFunc   ;==>_Excel_BookOpen

Func out()
    Exit
EndFunc

Can someone please help me.
All I want to do is show info in _richedit enumerated base on their values

 

Error is that _Excel_BookOpen or _Excel_BookOpenEX always return 2

Edited by senatin

Share this post


Link to post
Share on other sites
water

Modify this line:

Local $oWorkbook = _Excel_BookOpenEX($oExcel, @ScriptDir & "\Book2.xlsx", True) ; <== backslash added

 

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
senatin
1 hour ago, water said:

Modify this line:

Local $oWorkbook = _Excel_BookOpenEX($oExcel, @ScriptDir & "\Book2.xlsx", True) ; <== backslash added

 

Yah Its working now Thank you Now next step. Hope I can figureout it straight till the end

Edited by senatin

Share this post


Link to post
Share on other sites
water

BTW: There is no need to quote my post - I know what I have written ;)  Just enter a reply at the end of the thread.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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

×