Is there a way to disable the right click menu for shapes like e.g. rectangles in VBA?
I tried:
Private Sub Workbook_Open()
' Application.WindowState = xlMaximized
Application.DisplayFullScreen = True
Application.CommandBars("Ply").Enabled = False
Application.CommandBars("Shapes").Enabled = False
End Sub
but this does not seem to work.
The right-click menu (aka, context menu) is not a Command Bar.
You may know Command Bars by their older name, Toolbars, or their newer name, Ribbons.
Although you can capture and/or disable a right-click event on a worksheet, this doesn't apply to objects like shapes.
However, you can prevent the context menu from showing by protecting the worksheet from changes (with or without a password).
If necessary you can allow some changes, but not others, to be made by the user. More information at this link.
I have attached some screenshots of my application just to describe what I want to archive.
The problem is that the menu is realy annoying when trying to select more than one shape.
Related
I've gone through a number of tutorials and instructional videos trying to achieve my intended result of simply allowing a checkbox in my form to hide content when selected, or re-show it when being de-selected, but nothing seems to be working.
Currently, I've created a bookmark for the content I want hidden, and try to call his this in VBA with the following statement - which a number of resources indicated as the solution:
Private Sub CheckBox1_Click()
ActiveDocument.Bookmarks("bookmark").Range.Font.Hidden = CheckBox1.Value
End Sub
But despite doing this, selecting the checkbox has no affect on the content.
Is there something additional I'm missing (I'm using Microsoft Word 2013).
Your code worked fine when I tested it, but I ran into a few issues since I've never messed with userforms/checkboxs in Word VBA and I suspect you may have the same.
For instance, the first thing I did was create Insert --> Module. This is incorrect. What you want to do is Insert --> Userform then drag a checkbox over from the ToolBox
https://smallbusiness.chron.com/use-check-boxes-word-54673.html
Then double click the checkbox to bring up the "module" it would run, notice there is no module in the side pane! Edit the module, then go back to the userform and press F5. You should be presented with a checkbox that will hide/unhide your text.
Here is my module:
Public Sub CheckBox1_Click()
ActiveDocument.Bookmarks("bookmark").Range.Font.Hidden = CheckBox1.Value
End Sub
Here is an image:
Note: I didn't test how to insert the checkbox into the word doc, I'll leave you some of the learning!
Update:
This sub will make the CheckBox appear when run, but I'm not sure the logic you would use to call it, perhaps an event like opening of document?
Sub Loadform()
Load UserForm1
UserForm1.Show
End Sub
This could be called via a keyboard shortcut or event, but this will cause a "pop-up window". If you want an inform checkbox you may need to look into using this Legacy Form/Checkbox. I was following the URL from above but I think it's dated.
Update:
You could also add this easily to a toolbar, but that isn't likely what you want. I found the best way is to use a "field code" see --> https://word.tips.net/T001571_Assigning_a_Macro_to_a_Button_in_Your_Text.html
I was able to get this to work by pressing CTRL + F9 then typing { MacroButton Loadform ClickMe} then clicking this text. This may be the best bet as using an image seems not to be a great idea.. (https://answers.microsoft.com/en-us/msoffice/forum/all/using-graphic-with-macrobutton/a9c1ef3b-cf1f-48ba-92a8-c44bffcdc131) & (http://www.addbalance.com/usersguide/parts/macrobutton_fields.htm#Different_behavior)
Gif Example:
I have a PowerPoint loaded with VBA and quite a few slides. I would like to be able to manually advance the slides by pressing the {Page Down} key when I am the user running the presentation, but, I want the {Page Down} key not to work when any other user is running the presentation.
I know the following:
I have a function that easily will return the name of the user, so, I can easily compare the current user to myself and execute code based on the match/lack of match. No problem here.
I know that I can set the presentation type by using: ActivePresentation.SlideShowSettings.ShowType = ppShowTypeSpeaker.
I know that I can set the way slides are advanced by using: ActivePresentation.SlideShowSettings.AdvanceMode = ppSlideShowManualAdvance
The problem and things I've tried:
Once the PowerPoint has started, using VBA code to change the value of ShowType from the default setting of ppShowTypeKiosk to ppShowTypeSpeaker does not seem to change the way the rest of the show functions.
Once the PowerPoint has started, using VBA code to change the value of AdvanceMode to ppSlideShowManualAdvance does not actually enable me to manually advance slides (I am still only able to advance slides using the ActiveX buttons on the slide).
I have thought about using event handling to capture the SlideShowBegin event, but, apparently events can only be trapped once code has established the link to the Application object, and, making that link has to happen in code that runs by clicking an ActiveX control (or similar user action) in an already-running slideshow so I am baffled how the SlideShowBegin event would ever be trapped without an AddIn with an Auto_Open macro.
Bottom line: Is there a way for PowerPoint VBA code to switch a slideshow from kiosk to speaker mode so that slides can be manually advanced? (Or, some other way to enable me to manually advance slides while preventing all other users from manually advancing slides?)
Thanks to #SteveRindsberg, the fix is to (a) determine whether or not to switch presentation modes, then, (b) if a switch is needed, run the code to change the settings, then, (c) programmatically end the slideshow, then, (d) programmatically run the code to re-start the slideshow.
It is assumed that the PowerPoint has been saved to run in Kiosk mode by default so that the standard user cannot use PageDown or other navigation techniques to move through slides; that is, slides can only be navigated by the programmer's ActiveX controls that use VBA code to move through the slideshow. (This is handy for quiz-type slideshows, etc.)
Specifically, I have Slide 1 which includes an ActiveX [OK] button on it which the user is directed to click in order to continue; basically, Slide 1 is a title slide that gives the name of the PowerPoint. When the OK button is clicked, the code behind the [OK] button checks to see whether the user should be allowed to change the presentation mode from the default Kiosk mode to Speaker mode. Here's the code behind the [OK] button in Slide 1:
Private Sub cmdFeedbackOK_Click()
'handle the click of the OK button on the feedback which will move to the next slide or exit if the wrong OS or Office Version (based on text associated with the [OK] button
'check for superuser
If LCase(Environ("UserName")) = "{Windows username who is a superuser}" And ActivePresentation.SlideShowSettings.ShowType <> ppShowTypeSpeaker Then 'this will check to be sure that we have not already changed the ShowType (which will have changed if the user opts to switch modes and the PPTX has re-started)
'superuser, so, change to Speaker mode
If MsgBox("Do you want to switch to Speaker view instead of Kiosk view so you can use PageDown?", vbYesNo + vbDefaultButton1, "Use PageDown?") = vbYes Then
ActivePresentation.SlideShowSettings.ShowType = ppShowTypeSpeaker 'switch from Kiosk to Speaker mode so that PageDown key will work
ActivePresentation.SlideShowSettings.AdvanceMode = ppSlideShowManualAdvance 'switch to allow PageDown to manually advance the slides
ActivePresentation.SlideShowWindow.View.Exit 'exit the show because the change in play mode and advance mode will not take effect until the show is started again
ActivePresentation.SlideShowSettings.Run 'restart the show; code in the OnSlideShowPageChange will get triggered to skip this first slide if the user has restarted the show
Exit Sub
End If
End If
ActivePresentation.SlideShowWindow.View.Next 'move to next slide
End Sub
Then, to prevent the superuser from having to view the first slide twice when the slideshow re-starts, I have added the following code to the OnSlideShowPageChange event:
SlideName = ActivePresentation.SlideShowWindow.View.Slide.Name
If SlideName = "sldTitle" Then 'we're on the first slide
If ActivePresentation.SlideShowSettings.ShowType = ppShowTypeSpeaker Then 'this will be true if the Windows user is me (see code in Slide1), and, since I've already seen that slide, just go to the next slide
ActivePresentation.SlideShowWindow.View.Next 'skip the first slide for superuser
'execute other code as desired
'use Exit Sub here if the code below does not need to run for the superuser
End If
End If
'execute other code as desired here, e.g., code for standard users
For me, Slide 1 gives a lengthy delay (maybe 10 seconds) after clicking the [OK] button before the slideshow re-starts, but, the standard user does not experience the delay so I don't mind the wait--it probably has something to do with the VBA code and large number of slides in the presentation that have numerous ActiveX controls--at least, that's my guess.
Hope this helps someone out!
I have a custom ribbon which works fine but I only want to enable it and have my add in show for certain workbooks so I check for the workbook title on load and try to use the Invalidate method if the condition is false. Unfortunately nothing happens the custom ribbon tab is still showing.
The following is my sub:
Public Sub loadMyRibbon(ribbon As IRibbonUI)
Set RibUI = ribbon
If Not workbookTitle = "My Workbook" Then
If Not RibUI Is Nothing
RibUI.Invalidate
MsgBox "Not Working"
End If
End If
End Sub
Which seems correct to me from reading through the method documentation:
Microsoft Documentation
I see my MsgBox message displayed on the screen so I know the code is executing correctly up to that point but RibUI.Invalidate doesn't hide my tab. Appreciate any pointers!
I have also tried:
RibUI.InvalidateControl "myTag"
But this also doesn't work
Ribbon.Invalidate doesn't mean the ribbon will not show. Invalidate function just tells the ribbon to invalidate and re-initialize the ribbon controls with their default/dynamic properties.
I worked with few Add-ins where the clients wanted to hide the ribbon items if users cannot pass the authentication. So in such a case, I used "GetVisible" attribute in all of my Control and then I used this code
Sub GetVisible(control As IRibbonControl, ByRef Visible)
On Error Resume Next
Visible = shouldShowOrNot
End Sub
shouldShowOrNot is a boolean variable, which I set in Ribbon Load to true if user passes the authentication. See the following image:
Now the above image is a representation of Ribbon in case User has failed the authentication. There might be a better way to do it, but i found it to be the best way so far.
Hope this helps,
Vikas B
Is it possible to create a custom layout, existing ones are:
Print layout
Full Screen reading
Web layout
Outline
Draft
These can be found in the View Ribbon under the group Document Views.
My aim is to get my own layout button in either the existing View Ribbon (if it is possible to modify it) or add a new layout to my custom Ribbon.
Thanks in advance!
This answer is going to provide information on how to change standard settings of any view type control and associate these changes with certain document. This will not work with all documents and will not change the control action for whole Word Application but for one document. Operation could be repeated for few document and almost all Word button.
Important! I'm not using English version of Office application therefore some description will not match exactly to what you have. Tried and tested for Word 2010.
There are following steps to go:
Open new document- one where control should work according to your private expectations.
Go to View >> Macros >> Show list of macros
In the combo-box below middle of the Macro window choose something like Word application commands (or Word macros or similar). As a result you get list of lots of macros names.
You need to guess which of the macro is associated with ribbon control you are going to change. Use common sense and logic to find it. Sometimes two or three seems to match and possibly you will need to make a try.
A) let's try to change behaviour of draft/pending/working view ribbon control. one rounded red below:
B) find macro ViewNormal (but not ViewDraft)
C) select this macro on the list
Change back on the combo-box list to your document (while keeping your chosen macro selected)
Press Create button on the right in the macro window. You will be moved to VBA Editor to the following code:
Sub ViewNormal()
'
' ViewNormal Makro
' Zmienia widok edycji na normalny
'
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdNormalView
Else
ActiveWindow.View.Type = wdNormalView
End If
End Sub
This code is responsible for working of chosen ribbon control.
First, let's check if we can take control of ribbon button- add MsgBox "Control taken" at the end of the code, before End sub. Back to Word App and press button on the ribbon which result should be- setting of chosen view and our message box.
Now you need to change your code accordingly to set your view as you need. Use VBA for that.
Save document as .Docm and all the changes will be applied to the document each time you press chosen ribbon button.
I'm struggling to find out how to programmatically enable the "Select objects" cursor type. I checked the object browser and expected to find a property like Application.CursorType or Application.DrawingMode.
Changing the cursor type isn't picked up in the macro recorder and I must be searching for the wrong terms as I can't find information about this anywhere.
Edit: I should've made it clear I'm not talking about the cursor appearance that can be set via Application.Cursor. Rather, I want to set the cursor into the same mode as can be set via the GUI by clicking the "Select objects" icon on the Drawing toolbar. This is the cursor that only allows selection of shapes and ignores cells, text and the formula bar.
Actually, I never knew the correct name for this cursor mode until I checked the tooltip to write this update, perhaps that'll help.
I don't quite follow why you want to do this, but you can toggle the "Select Objects" drawing mode programmatically by executing the built-in CommandBar control:
Call CommandBars("Drawing").Controls("Select Objects").Execute
And you can determine the current mode by checking its state:
If CommandBars("Drawing").Controls("Select Objects").State Then
Call Debug.Print("Select Object mode is on")
End If
Good luck!
I'm a little 'late to the party' on this one but here is the answer to 'why he wants to do this' as well as 'what he wants to do'.
'Turn ON 'Select Objects' option during initial display. While ON, cell input is prevented.
If CommandBars("Drawing").Controls("Select Objects").State = False Then
CommandBars("Drawing").Controls("Select Objects").Execute
End If
I use this in a simple timer application which has one command button and two check boxes on the 'ActiveSheet' display. By turning ON 'Select Objects', I limit the cursor input targets to these three items. Cells cannot be selected.
Cheers,
Lawrence
Would this link help?
Here's a synopsis:
Over the application, you have four choices:
xlDefault
xlWait
xlBeam
xlNorthwestArrow
You call it like:
Application.Cursor = xlDefault
Over forms, you have more choices. See the article for more.
I don't know what you mean with 'drawing mode'. However, if you want to change the appearance of your mouse cursor, the property you are looking for is Application.Cursor
You can set it to one of four predefined values: xlWait, xlNorthwestArrow, xlIBeam and xlDefault.
If you want to display other cursors, have a look this article on how to display a custom cursor in Access. Since it uses the WinAPI, the solution should work equally in Excel.
Edit:
In response to your edit: I don't think that it is possible to do what you want. The macro recorder doesn't pick it up because there is no VBA command that can do it.
Depending and what you are trying to achieve by switching to design mode, there may be other ways though.
If you want to keep the user from changing the data in your workbook, you can hide the complete Excel window using the Application.Visible property.
If you want to keep the user from selecting or changinganything, but still display the data, have a look at ActiveSheet.Protect or ActiveWorkbook.Protect, available under Tools - Protection.
If you want to move or resize some controls in your workbook, you can do that programmatically by changing the Left, Top, Height and Width property of the control, you don't need to switch to design mode in order to do this from your macro.