As described in the solution here I created the following VBA to minimize the ribbon menu in Excel:
Sub Minimize_Ribbon()
SendKeys "^{F1}"
End Sub
However, when I run this VBA it opens the following link to the Help section from Microsoft:
https://learn.microsoft.com/de-de/office/vba/api/overview/language-reference?redirectedfrom=MSDN
I assume this issue is because somewhow the ^ which should run the Ctrl is not working in the VBA.
What do I need to change to make it work correctly?
As already described in the comments the solution is:
Sub Minimize_Ribbon()
CommandBars.ExecuteMso "MinimizeRibbon"
End Sub
Related
I need a workbook to display the Combobox List Dropdown when it opens.
The combobox in the Workbook is a form control, so a shape.
Cant seem to find the associated property.
If you are using ActiveX Controls then see the below, else if you are using Form Controls then replace them with ActiveX Controls if you want the drop down to happen via code. The below code will work for both ActiveX Controls in a Form as well as Worksheet. If the Control is on a worksheet then change ComboBox1.SetFocus to ComboBox1.Activate
Two ways I can think of...
Using a simple command
Tried And Tested
Private Sub CommandButton1_Click()
ComboBox1.DropDown
End Sub
Using Sendkeys. Sendkeys are unreliable if not used properly.
Tried And Tested
Private Sub CommandButton1_Click()
ComboBox1.SetFocus
SendKeys "%{Down}"
End Sub
SCREENSHOTS
I have had plenty of crashes with .dropdown but find some success with
the SendKeys...
I consider best
UserForm combo box is as Above by Siddharth Rout
ComboBox1.SetFocus
SendKeys "%{Down}"
for some Combo boxes on a worksheets
CB.DropDown Is enough
.. Just as well as they have no setfocus or activate
Does anyone here have any idea how to row Excel's built-in tool (see screenshot below) and automatically select specified window to capture using VBA Script?
What the code below does is essentially press the shortcut keys: Alt+N+SC+C, where Alt=%, N=Insert Ribbon, SC=Screenshot Button, C= Capture Screen Button, you may have to modify depending on language/office version/shortcut setup. I got it working by running the code from a form control button on the worksheet, running from VBA-editor did not work in this case.
Sub Screenshot()
SendKeys ("%NSCC"), True
End Sub
Note: You should only use the SendKeys Method if no other option is
available, because it can cause problems, if the wrong window is
active when the code runs.
_
Edit: As you have requested to pick one of the windows in the
screenshot gallery, i recommend you find the the SendKeys equivalent
of TAB and ENTER. Not the best solution i admit, but better than
nothing.
_
Edit2: See this brilliant answer:
I call a macro called SelectSheet1, from a button on a userform, to select Sheet1.
When data is entered afterwards it is put on the previous sheet.
This is happening on Excel 2013. I confirmed it is not a problem in Excel 2007.
Also it is not a problem if the macro is run directly from the developer tab, keyboard shortcut, quick access toolbar or ribbon customization.
The userform command button code:
Private Sub CommandButton1_Click()
Call SelectSheet1
Unload UserForm1
End Sub
The SelectSheet1 macro selects the sheet:
Sub SelectSheet1()
Sheets("Sheet1").Activate
End Sub
Link to xlsm file in dropbox
Link to youtube video if you want to see with your own eyes
It is a strange error and wondering if it a problem with Excel 2013, something changed in the way they do things and possibly there is a workaround.
Make sure there is only a single sheet Select'ed before you Activate a sheet:
Sub SelectSheet1()
Sheets("Sheet1").Select
Sheets("Sheet1").Activate
End Sub
Remember: "Although only a single sheet may be Active, many may be Selected."
I was able to figure out how to get it to work, but not sure why this solves the issue.
Im unloading the Userform before call macro and I tried using select instead of Activate, those did not help. But after I switched so that the UserForm loads with vbModeless then my problem went away, not sure why this fixed it.
For me the key to fixing this issue was vbModeless, but would love if somebody who understood more could explain why.
Private Sub CommandButton1_Click()
Unload UserForm1
Call SelectSheet1
End Sub
Sub ShowMainMenu()
UserForm1.Show vbModeless
End Sub
Sub SelectSheet1()
Sheets("Sheet1").Select
End Sub
Having just upgraded to Excel 2013, I've moved my macros from a legacy custom toolbar to a custom ribbon menu. All works well, except for one thing. I used to have a macro that ran on AutoOpen, but could also be called manually via a button on the toolbar.
I call my macro from the ribbon using Sub myMacro(control As IRibbonControl) which works. But if I Call myMacro(control As IRibbonControl) in AutoOpen I get an "expected list separator" error. Conversely if I just Call myMacro() in AutoOpen I obviously get a "argument not optional" error. Bit of a Catch 22!
I know that I could just move my code to a third sub-routine, called by two separate macros in the ribbon and in AutoOpen, but before I admit defeat and do this I wonder if there is a way around this.
I have searched the web for a solution to this, but couldn't find anything that answered my particular query.
Thanks
Rob
A simple code as this will help?
Option Explicit
Sub AutoOpen()
Dim ctl As IRibbonControl
myMacro ctl
End Sub
Sub myMacro(control As IRibbonControl)
MsgBox "Hello World"
End Sub
I'm making an auto-backup for excel and I cannot find a way to run a sub procedure (that starts a timer) in my custom "add-in" code.
I've found the Workbook_Activate or Workbook_Open sub but they must be created in the worksheet and not in the "add-in" therefore everyone who would want to use the backup feature from the add-in should write that code, which is not manageable.
Is there anyway?
thanks
Oh, sorry.. after I've asked it I've found this:
Private Sub Auto_Open()
startBackupTimer
End Sub
which works!