How to generate Tooltip, Quickinfo or Notification without Mouseover event in Word VBA? - vba

Is there any possibility in MS Word with VBA to show a short notification message to the user as he begins creating his Word document. I would like to display a short message to him, something like a notification (quickinfo, tooltip but control independent), which displays for about 30 seconds and dissapears automatically, so that the user doesn't have to close the window manually. Similar to the status messages in the system tray, but in Microsoft Word itself.

You can make a custom form and set ControlBox to false and FormBorderStyle to None.

Sure, there are lots of ways to do this. Some more complex than others. Probably the easiest would be to use a timer with the Application.StatusBar object and then some code like:
Sub StatusBarUpdate()
Application.StatusBar = "Hello"
End Sub

Related

How to manage application options/advanced options?

I need to quickly toggle File > Options > Advanced > Reminders > Play reminder sound setting.
In certain meetings I need to keep Outlook running to get reminders, but don't want the reminder sound.
Currently, I manually toggle the File > Options > Advanced > Reminders > Play reminder sound checkmark.
This needs to be an effective single-click.
I don't want to restart Outlook as there are usually many things open.
I cannot add it to the Quick Access Toolbar.
On the left the option is present in the list of QAT commands, but not in the list of Ribbon commands, otherwise we could access it with ExecuteMso.
Three reasons:
The button is disabled when not in the Calendar window. That's just inelegant.
When I click the button, Outlook crashes and I lose everything that wasn't saved. (Autosave isn't sufficient or functioning. That's a different problem.)
Understanding how to access Outlook settings with VBA opens a whole new world of possibilities.
This Microsoft article series starting at https://learn.microsoft.com/en-us/office/vba/outlook/concepts/getting-started/automating-outlook-from-a-visual-basic-application is about automating Outlook user tasks, like making a calendar appointment. That's not what I want, I want to manage Outlook's options.
There are some discussions about COM add-ins as one method, but that appears beyond me. The effort to learn COM add-ins is out of line with manual effort to achieve the desired goal.
I have some limited Outlook VBA experience but am reasonably comfortable with VBA in Word, Excel.
To disable reminder sound you need to set the below registry key to 0.
Registry key: PlaySound (REG_DWORD) to be set to 0.
Path: HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\options\Reminder
where 16.0 indicates the Outlook version.
Don't forget to restart Outlook to apply changes.
These settings can be overridden on the per appointment basis - you can simply set AppointmentItem.ReminderPlaySound property to false using VBA.
Simulate a button press with ExecuteMso.
https://learn.microsoft.com/en-us/office/vba/api/Office.CommandBars.ExecuteMso
Hover over the button where you would add it to the ribbon/QAT. See text in brackets at the end.
Are the command codes for ExecuteMso documented?
Private Sub ExecuteMso_TextInBrackets()
' https://learn.microsoft.com/en-us/office/vba/api/Office.CommandBars.ExecuteMso
' https://stackoverflow.com/questions/25610998/are-the-command-codes-for-executemso-documented
Dim oAppt As Object
Set oAppt = ActiveInspector.CurrentItem
Debug.Print oAppt.subject
ActiveInspector.CommandBars.ExecuteMso ("TextInBrackets")
End Sub
As with most things in life, the answer is a workaround. In this case, it's AutoHotkey to press the keys for me (ALT F, T, down x 9, ALT P, Enter):
;WIN-O toggles the Outlook alarm sound setting
#o::
SetTitleMatchMode,2 ;inexact match
WinGetActiveTitle, MyWindowTitle
If WinActive(" - email#company.com") ;Poor way to "prove" we're in Outlook
{
;MsgBox, We're in Outlook
Send !ft{Down 9}
Send !p{Enter}
}
Return

Show/Hide Footer Groupfooter in Report View NOT Print Preview

Good Day Mates, I have experience in MS Access but am stumped, maybe because MS Access just doesn't cut the mustard. In a nutshell, I am trying to build a Smart Report that does not need to be printed. Based on buttons clicked on the report, the report in REPORT VIEW (notice NOT Print Preview mode) and I want to HIDE or SHOW the Groupfooter based on the button clicks. Note: I am trying to avoid having numerous reports for each condition, just want a Smart Report to handle it.
Yes, Yes, Yes... I can make it work in PRINT PREVIEW using the Cancel command because the OnFormat event executes only in Print Preview mode.
Private Sub Groupfooter0_Format
If <condition> then
Cancel = True
End if
The OnPaint Event will NOT allow visibility commands to be set and gives an Error to that point, and the Cancel doesn't work either.
If <condition> Then
GroupFooter.Visible = True
Else
GroupFooter.Visible = False
End If
Again, I am hoping someone has experience with successfully hiding and showing groupfooters in REPORT VIEW using the OnPaint event and NOT the OnFormat event, because as explained, the user will control the report via buttons.
Cheers,

Using VBA to allow a checkbox to hide/show content in Microsoft Word

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:

Using PowerPoint VBA to change from a Kiosk presentation type to a Speaker presentation type

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!

What is the bare minimum VBA "I'm busy" dialog?

I've got a macro in PowerPoint 2010 that links audio files to each and every slide. However, this takes some time, and although there is a status bar "linking files" progress, I would like something more In your face.
Caveat: I'm really not familiar with VBA or it's API.
What I want:
ImBusyDialog("Linking Files...").Open()
// Call Sub that does real work.
ImBusyDialog.Close();
and that's it. If there's something built in like the page loading spinner in IE, then great, if not, I'm happy with a simple message box. The important thing is that it require no user intervention.
Use the same logic as you do to set the status bar. Where you set the statusbar text, you'll simply add the appropriate code to call a status dialog box.
O'Reilly has a rather detailed description on how to build a status bar dialog box with a progress bar and everything. It is probably a bit overkill for what you want, but more to see what is possible in VBA: http://oreilly.com/pub/h/2607
Stackoverflow has dealt with this issue before as well with a relatively simple box you could easily modify to show which file is being worked on an any given moment: How do I create a status dialog box in Excel
The important code from the previous post:
Sub ShowForm_DoSomething()r
Load frmStatus
frmStatus.Label1.Caption = "Starting"
frmStatus.Show
frmStatus.Repaint
'Load the form and set text
frmStatus.Label1.Caption = "Doing something"
frmStatus.Repaint
'code here to perform an action
frmStatus.Label1.Caption = "Doing something else"
frmStatus.Repaint
'code here to perform an action
frmStatus.Label1.Caption = "Finished"
frmStatus.Repaint
Application.Wait (Now + TimeValue("0:00:01"))
frmStatus.Hide
Unload frmStatus 'hide and unload the form
End Sub
The O'Reilly solution certainly is an involved solution, but it seems the "prettiest" and would probably be very user-friendly. The SO solution appears to be much easier to implement though.