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