Help with VBA

APML

Board Regular
Joined
Sep 10, 2021
Messages
216
Office Version
  1. 365
Hi all, I'm not very good at VBA, and had help achieving the following code from MrExcel. My problem is I only want it to work on the workbook called "Journal", but it
seems to work on all workbooks, hoping someone can advise on how to modify

This part is in "This Workbook" (Visual basic) in "Journal" workbook

Private Sub Workbook_Open()
Call Maximize_Workspace(True)
Application.OnKey "^z", "UnMaximize_Workspace"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Disable_Key
End Sub

This is the macro
Sub Test__Maximize_Workspace()
Call Maximize_Workspace(True)
End Sub
Sub Maximize_Workspace(trueOrFalse As Boolean)
If trueOrFalse = True Then
Application.DisplayStatusBar = False
Application.DisplayFormulaBar = False
ActiveWindow.DisplayHeadings = False
ActiveWindow.DisplayGridlines = False
Call Show_Top_Ribbon(False)
Else
Application.DisplayStatusBar = True
Application.DisplayFormulaBar = True
ActiveWindow.DisplayHeadings = True
ActiveWindow.DisplayGridlines = True
Call Show_Top_Ribbon(True)
End If
End Sub
Sub Test__Show_Top_Ribbon()
Call Show_Top_Ribbon(True)
End Sub
Sub Show_Top_Ribbon(hideUnhide As Boolean)
If hideUnhide = True Then
Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",True)"
Else
Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",False)"
End If
End Sub
Sub Disable_Key()
Application.OnKey "^z", "Do_Nothing"
End Sub
Sub Do_Nothing()
'Do nothing
End Sub
Sub UnMaximize_Workspace()
Call Maximize_Workspace(False)
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Upvote 0
Firstly, thanks for your help. So I'm not very good at VBA, in fact, I'm really poor at it.
So I'm not sure how I'm meant to be altering my code or where I should be putting your suggestion, can you pls advise? :)
 
Upvote 0
I don't understand. Are the macros in the workbook Journal ? Some of your other threads seem to indicate they are.
If they are why don't you just assign a shortcut key to the macro.

Also I hope you are the only one using the workbook because any other users are going to hate you for highjacking the shortcut key for "undo" (ctrl+z)
 
Upvote 0
I don't understand. Are the macros in the workbook Journal ? Some of your other threads seem to indicate they are.
If they are why don't you just assign a shortcut key to the macro.

Also I hope you are the only one using the workbook because any other users are going to hate you for highjacking the shortcut key for "undo" (ctrl+z)
Yes, the macros are in the workbook Journal. I actually never considered a shortcut key, it does make sense but the worksheet will be used
by others, so was wanting the macro to run on opening the workbook. I'm just very poor at VBA so wasn't understanding how to actually make the above changes that you suggested

And yes I do realise ctrl + z is a bad mistake so I'm going to change the letter.
 
Upvote 0
Try allocating a shortcut key using ctrl+shift+SomeLetter.

See if this makes it run just on the Journal workbook,

VBA Code:
Sub Test__Maximize_Workspace()
    If ThisWorkbook.Name = ActiveWorkbook.Name Then
        Call Maximize_Workspace(False)
    End If
End Sub
 
Upvote 0
Not sure why you started a new thread for this, when I already responsed to your question yesterday, and you never followed up on it:

In the future, please do not do that. Please keep it all to one thread, as Fluff explained.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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