Sign in to follow this  
Followers 0
Affe

Remove Excel Menu Bar (Office 2007)

10 posts in this topic

I'm trying to add an excel object into a GUI for the purpose of using it for graphing functions.

I'm currently stuck at the following example set of code, as I cannot seem to remove the menu that comes from Excel (note, you will need an excel file to open with this):

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;
; Embedding an Excel document inside an AutoIt GUI
;
; Limitations:
;
; 1. Integrating the GUI Menu with the Objects Menu does not work.
;   (they have seperate menu bars)
;

; Initialize my error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

;~ $FileName=@ScriptDir & "\Worksheet.xls"
$FileName = FileOpenDialog("Pick a file", @ScriptDir, "Excel Files (*.xls;*.xlsx)")

if not FileExists($FileName) then
  Msgbox (0,"Excel File Test","Can't run this test, because it requires an Excel file in "& $FileName)
  Exit
endif

$oExcelDoc = ObjGet($FileName) ; Get an Excel Object from an existing filename

if IsObj($oExcelDoc) then
    GUICreate ( "Embedded ActiveX Test", 640, 580, (@DesktopWidth-640)/2, (@DesktopHeight-580)/2 , $WS_MINIMIZEBOX +$WS_SYSMENU + $WS_CLIPCHILDREN)

    $GUI_ActiveX    = GUICtrlCreateObj  ( $oExcelDoc, 1, 95 , 400 , 300 )

    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 (@SW_SHOW)    ;Show GUI

   ; GUI Message loop
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE;or $msg = $GUI_FileExit
                ExitLoop
        EndSelect
    Wend

    GUIDelete ()

   ; Don't forget to close your workbook, otherwise Excel will stay in memory after the script exits !
    $oExcelDoc.Close (0)       ; Close the Excel workbook - Save prompt will not open

EndIf


Exit

; This is my custom error handler
Func MyErrFunc()
  $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

Is there any way to remove the menu bar? All I search seem to still have this issue unresolved.


[center][/center]

Share this post


Link to post
Share on other sites



Do you get an error by the COM error handler?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

No, I do not.


[center][/center]

Share this post


Link to post
Share on other sites

I see. Will do some testing tomorrow.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I searched the web and got the impression that you can't do it the way you do it now. You need to modify the User Interface.

Here is a document that describes what needs to be done.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

This is a snippet of code I wrote 4 years ago but it worked then and may give you some direction:

;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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

That's exactly the code the OP posted in his first post. I tried and it didn't work with the embedded Excel object (Excel 2010 32 bit on Windows 7 64 bit).

NB: I just tried with plain Excel and the embedded ActiveX component - doesn't work for both and returns no COM error.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Okay, I've been trying to see if I can get anywhere with the link you gave me, water.

This is what I have so far...

Below gives a COM error when trying to set the height (unspecified error, number 80020009) :

$oExcelDoc.Application.CommandBars("Ribbon").Controls(1).Height = 4

Below gives no error, but doesn't actually do anything. Note: Using a MsgBox prompt, I can actually read this information, as well as the height info above, I just can't change it...

$oExcelDoc.Application.CommandBars("Ribbon").Enabled = False
    $oExcelDoc.Application.CommandBars("Ribbon").Visible = False

Below gives me a COM error, stating that "The parameter is incorrect" (number 80020009 again):

$oExcelDoc.Application.CommandBars.ExecuteMso("MinimizeRibbon")

Below just showing the MsgBoxes that I used to see if I was indeed accessing the correct parameters:

MsgBox(0, "", $oExcelDoc.Application.CommandBars("Ribbon").Controls(1).Height)
    MsgBox(0, "", $oExcelDoc.Application.CommandBars("Ribbon").Visible)

Anyone able to expand on this, maybe show me where I'm going wrong?


[center][/center]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hello, sorry if I'm committing the crime of "necro-ing" a thread here but having received lots of help from this community, I just felt obliged to post this working version (at least in my 32-bit Win XP PC with MS Excel 2010) for the benefit of those who still need this:

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;
; Embedding an Excel document inside an AutoIt GUI
;
; Limitations:
;
; 1. Integrating the GUI Menu with the Objects Menu does not work.
;   (they have seperate menu bars)
;

; Initialize my error handler
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

;~ $FileName=@ScriptDir & "\Worksheet.xls"
$FileName = FileOpenDialog("Pick a file", @ScriptDir, "Excel Files (*.xls;*.xlsx)")

If Not FileExists($FileName) Then
    MsgBox(0, "Excel File Test", "Can't run this test, because it requires an Excel file in " & $FileName)
    Exit
EndIf

$oExcelDoc = ObjGet($FileName) ; Get an Excel Object from an existing filename

If IsObj($oExcelDoc) Then
    GUICreate("Embedded ActiveX Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_MINIMIZEBOX + $WS_SYSMENU + $WS_CLIPCHILDREN)

    $GUI_ActiveX = GUICtrlCreateObj($oExcelDoc, 1, 95, 400, 300)

    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
    ControlHide("Embedded ActiveX Test", "", "[CLASS:EXCEL2; INSTANCE:1]")
    ControlHide("Embedded ActiveX Test", "", "[CLASS:EXCEL2; INSTANCE:2]")
    GUISetState(@SW_SHOW) ;Show GUI

    ; GUI Message loop
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE ;or $msg = $GUI_FileExit
                ExitLoop
        EndSelect
    WEnd

    GUIDelete()

    ; Don't forget to close your workbook, otherwise Excel will stay in memory after the script exits !
    $oExcelDoc.Close(0) ; Close the Excel workbook - Save prompt will not open

EndIf


Exit

; This is my custom error handler
Func MyErrFunc()
    $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   ;==>MyErrFunc

 

I simply added these lines:

ControlHide("Embedded ActiveX Test", "", "[CLASS:EXCEL2; INSTANCE:1]")
ControlHide("Embedded ActiveX Test", "", "[CLASS:EXCEL2; INSTANCE:2]")

 

Edited by Mingre
Specified MS Office version

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  
Followers 0

  • Similar Content

    • Dimmae
      By Dimmae
      Hello,
      at first: i'm new here, so please forgive me my mistakes, and show them to me, just that i can learn to do better in the future.
      Now to my Problem: i have an excel sheet, where i just need some columns for further actions, but i have no idea how to add single columns to a new array.
      I found the following code(the one i just added as a file) from 'water' in this forum, but i wont get how i could add multiple columns into a new array.
      The biggest problem in my situation is that i dont know the count of the rows i need for the array, i just got a fix number of rows, which is 4.
       
      Hope you can help me, and sry again for this 'unlucky illustration'.
       
      btw: how can i add code shown as code here, instead of posting it as a attached file?.
       
       
       
      autoit-select-column.au3
      defects.xlsx
    • LoneWolf_2106
      By LoneWolf_2106
      Hi,
      i have an error:
      ==> The requested action with this object has failed.: $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count $iRowCount = .Range(^ ERROR  
      My code is:
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) Sleep(1000) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count Sleep(1000) _Excel_RangeWrite($oWorkbook_1, $oWorkbook_1.ActiveSheet,$aFileList[$i][2] , "AB3:AB"&$iRowCount) I have added some sleep because the application was crashing more often before, so i thought to slow down the code execution.
      But i didn't solve the issue.
      Has anyone an idea of what the problem might be?
      Thanks in advance.
    • water
      By water
      Extensive library to control and manipulate Microsoft Excel charts.
      Written by GreenCan and water.
      Theads: General Help & Support - Example Scripts
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2017-07-21)
      None. The COM error handling related bugs have been fixed.
       
    • LoneWolf_2106
      By LoneWolf_2106
      Hi,
      i have a problem with the deletion of an empty row in Excel.
      My code:
       
      If $vRow_2 = "" Then _Excel_RangeDelete($oWorkbook_1.ActiveSheet,"2", $xlShiftUp,1) EndIf I want to delete the second row. $vRow_2 is an empty cell, "A2".
      After running the code, the second row is not deleted.
      I have tried also:
       
      If $vRow_2 = Null Then _Excel_RangeDelete($oWorkbook_1.ActiveSheet,"2", $xlShiftUp,1) EndIf But it doesn't work.
      Any suggestion?
      Thanks in advance.
    • VeryGut
      By VeryGut
      I'm trying to insert the following formula in cell A2 using my script:
      =if(A1=""; "YES"; "NO")
      To my understanding, the line of code should be similar to this:
      _Excel_RangeWrite($MasterFile, Default, "=if(A1=""; "YES"; "NO")", "A2")
      However, it does not work, probably due to the multiple quotation marks that confuse the script :C
      How do I avoid this problem?