Jump to content
Sign in to follow this  
Bert

embedded Excel issue

Recommended Posts

Bert

I have a script that embeds a excel object into a gui. Works fine. I've noticed that the embedded excel object will get corrupted from a visual aspect if another window gets on top of the GUI then removed. The displayed corruption can be removed if I scroll down to hide all the corruption, then scroll back. Not a good solution by any means. This is what it looks like if I were for example to open notepad, have that window have focus on top of the gui , then close notepad giving the GUI focus again.

$FileName = @ScriptDir&'\book1.xls'
If Not FileExists($FileName) Then
    MsgBox(0, "ERROR", "File not found")
    Exit
EndIf

;Basic GUI
$oExcelDoc = ObjGet($FileName); Get an Excel Object from an existing filename
If IsObj($oExcelDoc) Then
    $mainGUI = GUICreate("viewer", @DesktopWidth - 50, @DesktopHeight - 150, 10, 10, $WS_MINIMIZEBOX +$WS_SYSMENU);,  $WS_CLIPCHILDREN) 
    $GUI_ActiveX = GUICtrlCreateObj($oExcelDoc, 10, 70, @DesktopWidth - 75, @DesktopHeight - 260)
;------------------

;Turns off all command bars in excel to prevent user from making changes
    For $Bar In $oExcelDoc.CommandBars
        If $Bar.Enabled = True Then $Bar.Enabled = False
        If $Bar.Visible = True Then $Bar.Visible = False
    Next
    $oExcelDoc.Application.DisplayFormulaBar = False
    $oExcelDoc.Application.CommandBars("Shadow Settings").Visible = False
    $oExcelDoc.Application.DisplayScrollBars = True
    $oExcelDoc.Application.DisplayStatusBar = False

Is there a different way to embed the object so that it won't get corrupted when this happens? Or a way to refresh the screen?

Edited by Volly

Share this post


Link to post
Share on other sites
dbzfanatic

I don't know about a different embed method but why not just set it to always on top or send a $WM_PAINT message to redraw the window so there isn't any corruption. If the window is active then don't send, if it's not the active window get ready and when it's active again send the message,just my idea.

Share this post


Link to post
Share on other sites
footswitch

Hey there.

Updated code:

#include <WindowsConstants.au3>

$FileName = @ScriptDir&'\book1.xlsx'
If Not FileExists($FileName) Then
    MsgBox(0, "ERROR", "File not found")
    Exit
EndIf

;Basic GUI
$oExcelDoc = ObjGet($FileName); Get an excel Object from an existing filename
If IsObj($oExcelDoc) Then
    $mainGUI = GUICreate("viewer", @DesktopWidth - 50, @DesktopHeight - 150, 10, 10, $WS_MINIMIZEBOX +$WS_SYSMENU + $WS_CLIPCHILDREN)
    $GUI_ActiveX = GUICtrlCreateObj($oExcelDoc, 10, 70, @DesktopWidth - 75, @DesktopHeight - 260)
Else
    MsgBox(0,"","failed")
EndIf
;------------------

;Turns off all command bars in excel to prevent user from making changes
For $Bar In $oExcelDoc.CommandBars
    If $Bar.Enabled = True Then $Bar.Enabled = False
    If $Bar.Visible = True Then $Bar.Visible = False
Next
$oExcelDoc.Application.DisplayFormulaBar = False
$oExcelDoc.Application.CommandBars("Shadow Settings").Visible = False
$oExcelDoc.Application.DisplayScrollBars = True
$oExcelDoc.Application.DisplayStatusBar = False

GUISetState()

While 1
    Sleep(500)
WEnd

Any hints as to make this work without the toolbars and so forth? Just the cells...

Regards,

footswitch


Share this post


Link to post
Share on other sites
Donnovan

This, in VBA, make the Excel to show only the grid cells: Application.DisplayFullScreen = True

I added the line "$oExcelDoc.Application.DisplayFullScreen = True" and got a error from Autoit. Not sure why.

Share this post


Link to post
Share on other sites
CrimsonTide

This, in VBA, make the Excel to show only the grid cells: Application.DisplayFullScreen = True

I added the line "$oExcelDoc.Application.DisplayFullScreen = True" and got a error from Autoit. Not sure why.

Add "$oExcelDoc.Application.DisplayFullScreen = True" before Guictrlcreateobj is called

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
Sign in to follow this  

×