the following codes are not working: Option Explicit ' Module Level Variables (Optional…
- User
the following codes are not working: Option Explicit ' Module Level Variables (Optional - for cleaner code) Dim hideStatusBar As Boolean Dim hideFormulaBar As Boolean Dim hideRibbon As Boolean ' For Excel 2010 and later
Private Sub Workbook_Open() ' Set variables based on your preference (True to hide, False to show) hideStatusBar = True hideFormulaBar = True hideRibbon = True ' For Excel 2010 and later
' Hide elements based on variables If hideStatusBar Then Application.DisplayStatusBar = False If hideFormulaBar Then Application.DisplayFormulaBar = False If hideRibbon And Application.Version >= 14 Then ' Check for Excel 2010 or later ThisWorkbook.Application.CommandBars("Ribbon").Visible = False End If End Sub
Private Sub Workbook_Close() ' Restore elements (code remains the same) Application.DisplayStatusBar = True Application.DisplayFormulaBar = True If Application.Version >= 14 Then ' Check for Excel 2010 or later ThisWorkbook.Application.CommandBars("Ribbon").Visible = True End If End Sub
- Assistant
It looks like there is a small mistake in the code. Instead of
ThisWorkbook.Application.CommandBars("Ribbon"), it should beApplication.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"", True)"to show the Ribbon again.Here is the corrected code:
Option Explicit ' Module Level Variables (Optional - for cleaner code) Dim hideStatusBar As Boolean Dim hideFormulaBar As Boolean Dim hideRibbon As Boolean ' For Excel 2010 and later Private Sub Workbook_Open() ' Set variables based on your preference (True to hide, False to show) hideStatusBar = True hideFormulaBar = True hideRibbon = True ' For Excel 2010 and later ' Hide elements based on variables If hideStatusBar Then Application.DisplayStatusBar = False If hideFormulaBar Then Application.DisplayFormulaBar = False If hideRibbon And Application.Version >= 14 Then ' Check for Excel 2010 or later Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"", False)" End If End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) ' Restore elements (code remains the same) Application.DisplayStatusBar = True Application.DisplayFormulaBar = True If hideRibbon And Application.Version >= 14 Then ' Check for Excel 2010 or later Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"", True)" End If End Sub - User
How can I use VBA to show my hidden menus in a workbook
- Assistant
To show hidden menus in a workbook using VBA, you can create a macro that resets the visibility of the menus to their default state. Here is a sample code that shows how to do this:
Option Explicit Sub ShowHiddenMenus() ' Show the status bar Application.DisplayStatusBar = True ' Show the formula bar Application.DisplayFormulaBar = True ' Show the ribbon (for Excel 2010 and later) If Application.Version >= 14 Then Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"", True)" End If MsgBox "Hidden menus have been shown." End SubTo run this macro, you can press
Alt + F11to open the Visual Basic for Applications (VBA) editor, go toInsert -> Moduleto create a new module, and then paste the above code into the module.Afterwards, you can run the
ShowHiddenMenusmacro by pressingAlt + F8, selectingShowHiddenMenus, and clickingRun. This will show the hidden status bar, formula bar, and ribbon in your workbook. - User
Can you write this code to be paste values only: ' Copy the row B:J to TContractors sheet pasteRow = tContsWs.Cells(tContsWs.Rows.Count, "B").End(xlUp).Row + 1 ws.Range("B" & i & ":J" & i).Copy Destination:=tContsWs.Range("B" & pasteRow & ":J" & pasteRow)
- Assistant
To paste values only from the copied range to the destination range, you can modify the code by using the
.PasteSpecial Paste:=xlPasteValuesmethod after copying the range. Here's the updated code:' Copy the row B:J to TContractors sheet pasteRow = tContsWs.Cells(tContsWs.Rows.Count, "B").End(xlUp).Row + 1 ws.Range("B" & i & ":J" & i).Copy tContsWs.Range("B" & pasteRow).PasteSpecial Paste:=xlPasteValues Application.CutCopyMode = False ' Clear the clipboardIn this modified code, the
Copymethod is used to copy the range from worksheetws, and thePasteSpecial Paste:=xlPasteValuesmethod is used to paste only the values to the range in thetContsWsworksheet. TheApplication.CutCopyMode = Falseline is included to clear the clipboard after pasting.You can replace the original code snippet with this updated version in your VBA script. This will ensure that only values (not formulas or formatting) from the copied range are pasted to the destination range.
Let me know if you have any further questions or need more assistance.