Jump to content
HarishIyer

Embed Blank Excel in GUI

Recommended Posts

Posted (edited)

HI Guys,

 

I got the below code from autoit . It basically embeds a blank word in a gui.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

Main()

Func Main()
    Local $oWordApp = ObjCreate("Word.Application")
    Local $oWord = ObjCreate("Word.Document")
    $oWord.Activate
    Local $oWordEvent = ObjEvent($oWord, "WordEvent")
    Local $hWnd = GUICreate("Test", 800, 600, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
    GUICtrlCreateObj($oWord, 10, 155, 300, 300)
    GUICtrlCreateTab(0, 0, 800, 600, $WS_CLIPSIBLINGS)
    GUICtrlCreateTabItem("Test1")
    GUICtrlCreateTabItem("Test2")
    GUICtrlCreateTabItem("")
    For $oCommandBar In $oWord.CommandBars
        If $oCommandBar.Type < 2 Then
            $oCommandBar.Enabled = False
        EndIf
    Next
    $oWord.CommandBars("Reviewing").Visible = False
    $oWord.CommandBars("Standard").Visible = False
    $oWord.CommandBars("Formatting").Visible = False
    $oWord.Activewindow.DisplayRulers = False
    $oWord.Activewindow.Split = False
    $oWord.Activewindow.SplitVertical = 0
    $oWord.Application.DisplayScrollBars = False
    $oWord.Activewindow.View.Type = 6
    $oWord.Activewindow.View.DisplayPageBoundaries
    GUISetState(@SW_SHOW, $hWnd)
    While WinExists($hWnd)
        Local $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then GUIDelete()
    WEnd
EndFunc  ; Main()

Func WordEvent($sEvent)
    TrayTip("", "Event: " & $sEvent, 5)
EndFunc

Func MyErrFunc()
  Local $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext )
  SetError(1); to check for after this function returns
Endfunc

I tried to change it for Excel as below.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
 $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

Main()

Func Main()
    $VersionNumber = '3.01'
    Local $oExcel = ObjCreate("Excel.Application")
    $oExcel.Visible = 1                                        ; Let Excel show itself
    $oExcel.WorkBooks.Add

        Sleep(2000)
        Local $hWnd = GUICreate("aa" & $VersionNumber, @DesktopWidth , @DesktopHeight - 45,-1,-1, $WS_MINIMIZEBOX + $WS_SYSMENU + $WS_CLIPCHILDREN)
    GUICtrlCreateObj($oExcel, -1, -1, @DesktopWidth - 10, @DesktopHeight -75)

    GUISetState(@SW_SHOW, $hWnd)
    While WinExists($hWnd)
        Local $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then GUIDelete()
    WEnd
EndFunc  ; Main()

Func MyErrFunc()
  Local $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext )
  SetError(1); to check for after this function returns
Endfunc

It shows a COM Error. 

Can anyone help me in converting word.Document to excel. 

Many Thanks,

Harish

Edited by HarishIyer
spleeing mistake

Share this post


Link to post
Share on other sites

Check ObjEvent for how to add a COM error handler. 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
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

Hi Water,

 

Thanks for the reply.

The error description is 

OK
We intercepted a COM Error !

err.description is:     
err.windescription:    Unspecified error

err.number is:     80004005
err.lastdllerror is:     0
err.scriptline is:     15
err.source is:     
err.helpfile is:     
err.helpcontext is:     
 

Share this post


Link to post
Share on other sites

Details can be found here https://docs.microsoft.com/en-us/windows/desktop/seccrypto/common-hresult-values

Unfortunately we have not enough error details (at the moment). 

Let me investigate how to get more info 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
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

HI Water,

 

I found objget to work but objcreate doesnt work!

In the example you can see for word.application objget works but fails for excel

 

Many Thanks,

Harish Iyer

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

×
×
  • Create New...