Sendkeys and minimising ribbon problem

mps

New Member
Joined
Feb 7, 2011
Messages
42
Hi I am trying to minimise the ribbon in workbook when it loads using the following code:

Code:
Private Sub Auto_Open()
If CommandBars("Ribbon").Height > 100 Then
    Application.SendKeys "^{F1}", False  'make sure ribbon is minimised
    MsgBox ("minimised")    
End If
End Sub

Frustratingly it checks the the ribbon height ok, but all sendkeys ends up doing is showing Excel help, rather than minising the ribbon. For some reason it is not picking up ^ as 'ctrl'.

Can anyone help? I do only want the ribbon minimised and not hidden, so the the user can still access excel's menus.
 
Finally after a lot of fiddling around and trying different combinations my maximise ribbon on close code works. The problem? Changing 'application.sendkeys' to just 'sendkeys' in the beforeclose event made it work! Where as I needed the word application before commandbars on loading the workbook to make the ribbon minimise, on closing the the workbook I needed to take out the word application from in front of sendkeys .... how crazy is that!! Either something is going on I don't understand or VBA is just a bit crazy here!!

The working code is as follows:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Application.CommandBars("Ribbon").Height < 80 Then
    SendKeys ("^{F1}")
    DoEvents
End If
'make sure workbook is saved before closing
ActiveWorkbook.Save
End Sub

Hope this helps someone else to avoid having a headache trying work this out!
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
The users who will be using my worksheet are not excel 'power' users and therefore do not know how to minimise / maximise the ribbon manually

This is not something that falls in the domain of advanced excel knowledge. You would do better to show your user how to minimize the ribbon *if that is their preference*.

ξ
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top