Jump to content

Excel app (using Locdarwin UDF)


Recommended Posts

BUTON "ADD DATA" is not working ??

#include <ExcelCOM_UDF.au3>  
#include <GUIConstants.au3>


$Form1 = GUICreate("TEST", 276, 191, 193, 115)
$OPEN = GUICtrlCreateButton("OPEN EXCEL ", 24, 24, 217, 49, 0)
$ADD = GUICtrlCreateButton("ADD DATA ", 24, 88, 217, 57, 0)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OPEN
            OPEN()
        Case $ADD   
            ADD() 
    EndSwitch
WEnd

Func OPEN() 
$sFilePath = FileOpenDialog("Open Word File", @ScriptDir, "Word Doc (*.XLS)")

If @error Then
   MsgBox(4096,"Process Interrupted ", " Process Interrupted by user /System Error ! ")
ENDIF

$oExcel = _ExcelBookOpen($sFilePath, 1)
$sReadCell = _ExcelReadCell($oExcel, "C15")
MsgBox(0, "Cell C15", $sReadCell)
$sReadCell = _ExcelReadCell($oExcel, "E21")
MsgBox(0, "Cell E21", $sReadCell)
EndFunc 


Func ADD() 
    DIM $oExcel
    _ExcelWriteCell($oExcel, 46, "A1") 
    EndFunc
Link to comment
Share on other sites

This seems to work for me:

#include <ExcelCOM_UDF.au3>
#include <GUIConstants.au3>

$Form1 = GUICreate("TEST", 276, 191, 193, 115)
$Open = GUICtrlCreateButton("OPEN EXCEL ", 24, 24, 217, 49, 0)
$Add = GUICtrlCreateButton("ADD DATA ", 24, 88, 217, 57, 0)
GUISetState(@SW_SHOW)

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $GUI_EVENT_CLOSE
         Exit
      Case $Open
         $sFilePath = FileOpenDialog("Open Excel File", @ScriptDir, "Excel Workbook (*.XLS)")
         If @error Then
            MsgBox(4096, "Process Interrupted ", " Process Interrupted by user /System Error ! ")
         EndIf
         $oExcel = _ExcelBookOpen ($sFilePath, 1)
         $sReadCell = _ExcelReadCell ($oExcel, "C15")
         MsgBox(0, "Cell C15", $sReadCell)
         $sReadCell = _ExcelReadCell ($oExcel, "E21")
         MsgBox(0, "Cell E21", $sReadCell)
      Case $Add
         _ExcelWriteCell ($oExcel, 46, "A1")
   EndSwitch
WEnd

Link to comment
Share on other sites

You need to make $oExcel global so that other functions can access it.

#include <ExcelCOM_UDF.au3>  
#include <GUIConstants.au3>

$Form1 = GUICreate("TEST", 276, 191, 193, 115)
$OPEN = GUICtrlCreateButton("OPEN EXCEL ", 24, 24, 217, 49, 0)
$ADD = GUICtrlCreateButton("ADD DATA ", 24, 88, 217, 57, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OPEN
            OPEN()
        Case $ADD    
            ADD()
    EndSwitch
WEnd

Func OPEN()
    $sFilePath = FileOpenDialog("Open Excel File", @ScriptDir, "Excel Workbook (*.XLS)")
    If @error Then
       MsgBox(4096,"Process Interrupted ", " Process Interrupted by user /System Error ! ")
    Else
        Global $oExcel = _ExcelBookOpen($sFilePath, 1)
        $sReadCell = _ExcelReadCell($oExcel, "C15")
        MsgBox(0, "Cell C15", $sReadCell)
        $sReadCell = _ExcelReadCell($oExcel, "E21")
        MsgBox(0, "Cell E21", $sReadCell)
    EndIf
EndFunc

Func ADD()
    If IsDeclared ("oExcel") Then
        _ExcelWriteCell($oExcel, 46, "A1")
    Else
        MsgBox(0,"Error", "You must open an Excel file first.")
    EndIf
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...