Disable Min Max restore buttons

P

PeteSmith

How do I Hide / disable Min/Max/Close buttons in XLapp and XlWorkbook windows
If cant be done then how can i direct code towards a button on a form which sits over the spreadsheet and perform the button click event of that for
I am automating excel for VB.net
Cheer
pete
 
M

Michel Pierron

Hi Pete,
Perhaps like that:

Set xlApp = WScript.CreateObject("Excel.Application")
Set xlWbk = xlApp.Workbooks.Add
xlApp.ActiveWorkbook.VBProject.VBComponents.Add(1).Name = "TmpModul"
AddCodeLine "TmpModul", "Private Declare Function FindWindowA Lib ""User32""
(ByVal lpClassName$, ByVal lpWindowName$) As Long"
AddCodeLine "TmpModul", "Private Declare Function SetWindowLongA Lib ""User32""
(ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&) As Long"
AddCodeLine "TmpModul", "Private Declare Function DrawMenuBar Lib ""User32""
(ByVal hWnd&) As Long"
AddCodeLine "TmpModul", ""
AddCodeLine "TmpModul", "Sub LockExcel()"
AddCodeLine "TmpModul", "ActiveWindow.WindowState = xlMaximized"
AddCodeLine "TmpModul", "ThisWorkbook.Unprotect"
AddCodeLine "TmpModul", "ActiveWindow.WindowState = xlMaximized"
AddCodeLine "TmpModul", "Dim hWnd As Long"
AddCodeLine "TmpModul", "hWnd = FindWindowA(vbNullString, Application.Caption)"
AddCodeLine "TmpModul", "SetWindowLongA hWnd, -16, &H15470000"
AddCodeLine "TmpModul", "DrawMenuBar hWnd"
AddCodeLine "TmpModul", "ThisWorkbook.Protect Structure:=False, Windows:=True"
AddCodeLine "TmpModul", "End sub"
xlApp.Visible = True
xlApp.Run xlWbk.Name & "!LockExcel"
With xlApp.ActiveWorkbook.VBProject.VBComponents
.Remove .Item("TmpModul")
End With
' ...

Set xlWbk = Nothing
Set xlApp = Nothing

Sub AddCodeLine(strComponentName, strCodeLine)
With xlApp.ActiveWorkbook.VBProject.VBComponents(strComponentName).CodeModule
.InsertLines .CountOfLines + 1, strCodeLine
End With
End Sub

MP

PeteSmith said:
How do I Hide / disable Min/Max/Close buttons in XLapp and XlWorkbook windows.
If cant be done then how can i direct code towards a button on a form which sits
over the spreadsheet and perform the button click event of that form
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top