3

I am trying to hide my ribbons upon my workfile opening.

I've followed the below link but keep getting run-time error 91. VBA auto hide ribbon in Excel 2013

I've written the following code on the "thisworkbook" mode, but cannot get the line to work.

 Private Sub Workbook_Open()
 CommandBars.ExecuteMso "HideRibbon"
 End Sub
peterh
  • 11,875
  • 18
  • 85
  • 108
PGD15
  • 183
  • 2
  • 15

1 Answers1

3

You need to add Application in front of CommandBars.

 Private Sub Workbook_Open()
    application.CommandBars.ExecuteMso "HideRibbon"
 End Sub
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
PGD15
  • 183
  • 2
  • 15
  • this is the answer many thanks to Kdavies – PGD15 Oct 30 '18 at 15:53
  • 2
    Don't thank me - was BigBen's suggestion. I also flagged to see if mod would merge with this question's dupe - unless you want to post this answer there and we can just close this as a dupe. – K.Dᴀᴠɪs Oct 30 '18 at 15:57
  • would be better to merge into other post i think, as this is a duplicate question just didn't adapt for 2016 version. – PGD15 Oct 30 '18 at 16:09
  • 1
    seems not to be a 2016 issue `CommandBars.ExecuteMso "HideRibbon"` works for me in 2016 without error (in a module). But it fails in `ThisWorkbook`. So this is related to in which scope the code is placed. – Pᴇʜ Oct 30 '18 at 16:10
  • Apologises thanks to BigBen. – PGD15 Oct 30 '18 at 16:13
  • Oh, Peh where did you add the code then? I tried in a worksheet and only works if i trigger that tab not when file was opened – PGD15 Oct 30 '18 at 16:13
  • @PGD15 In a module it works without `Application.` but not in `ThisWorkbook`. Anyway it is a very good idea to use it with `Application.` – Pᴇʜ Oct 30 '18 at 16:15
  • @Pᴇʜ yeah i used application for lots of my other code just didn't think to use it for this! :( – PGD15 Oct 30 '18 at 16:18