Auto navigate WebBrowser in PPT - browser

In one page of my ppt, I insert a WebBrowser control. I want this WebBrowser navigate to a URL automatically when this page is on the show.
Currently I have to insert a CommandButton and set like this:
Private Sub CommandButton1_Click()
WebBrowser1.Navigate "url", 0, 0, 0, 0
End Sub
Plz how can I let it be triggered automatically instead click the CommandButton?

This page on Chirag Dalal's site explains the OnSlideShowPageChange event
http://officeone.mvps.org/vba/run_macro_at_slide.html
As implied by the name, it only fires during slide shows.

Related

Excel VBA - Ribbon - Set value of EditBox

I have a custom tab on the excel ribbon with an EditBox. The user should enter a number between 100 and 200 in the EditBox. If the user enters anything other than that, then an error message should pop-up and the text in the EditBox should change to 100. The last part is the one I'm having difficulty with, setting the EditBox text to "100".
'Callback for EditBox onChange event
Sub setQVal(control As IRibbonControl, ByRef text)
If Not IsNumeric(text) Or text < 100 Or text > 200 Then
MsgBox "Error! Please enter a value between 100 and 200."
text = 100 'This doesn't seem to work
Exit Sub
End If
QVal = text
End Sub
Any assistance would be appreciated
The signature of the onChange callback should look like this:
Sub OnChange(control As IRibbonControl, text As String)
To change the text you need to implement the getText callback:
Function GetText(control As IRibbonControl) As String
The getText callback is invoked by the Office applications when the Ribbon UI is invalidated. So, you need to force the UI to invoke callbacks. For each of the callbacks that the code implements, the responses are cached.
For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in place for the control until the add-in signals that the cached values are invalid by using the InvalidateControl method, at which time, the callback procedure is again called and the return response is cached.
In the following example, starting the host application triggers the onLoad event procedure that then calls a procedure that creates an object representing the Ribbon UI. Next, a callback procedure is defined that invalidates a control on the UI and then refreshes the UI.
<customUI … OnLoad="MyAddInInitialize" …>
And in the code, if you need to update the text (get the getText callback invoked) you need to use the following approach:
Dim MyRibbon As IRibbonUI
Sub MyAddInInitialize(Ribbon As IRibbonUI)
Set MyRibbon = Ribbon
End Sub
Sub myFunction()
MyRibbon.InvalidateControl("editBoxControlID") ' Invalidates the cache of a single control
End Sub

Is there a way to detect if user clicked a disabled button?

Hey, I have an UserForm into which an user inputs varius profile
fields.
Once it's filled in, there is verification - if anything goes astray,
the CommandButton, named save_button is disabled
What I want to achieve is: If user clicks on the button, whilst it is in the disabled state, to display a MsgBox saying he needs to correct the incorrectly filled in field
For Demonstration purposes, I'm not gonna paste here the validation procedures, so let's just pretend that the save_button.Enabled = False is set from the getgo. Produces the same result.
save_button.Enabled = False ' already ran before, pretend this executes it
Private Sub save_button_Click()
If save_button.Enabled = False Then
MsgBox "Clicked disabled button"
End If
End Sub
Issue is, once a CommandButton is set to .Enabled = False then it can no longer be officially clicked (hence it can't even trigger the Click() procedure)
My next thought was to use the MouseUp as a substitute. Issue is,
this triggers on any miniscule movement over the button and I don't want to bombard the user with MsgBoxes
Can you think of any alternatives, as to how to detect if user clicked the disabled button?
When a control is disabled, the click event bubbles up the tree. In your case, I guess the user form will get the click instead. If you put your save button inside a frame, that will get the click if the button is disabled. It is fairly easy to make the frame invisible, by setting
Caption to ""
BorderStyle to fmBorderStyleNone
SpecialEffect to fmSpecialEffectFlat
And then size the frame so that is the same size as the button.
The code is easy:
Private Sub YourNewFrame_Click()
MsgBox "Save button disabled!"
End Sub
Tip: If you draw the frame, cut your button and paste it inside your new frame, it will be placed properly. Properly, as in in the right part of the hierarchy. Visually, you will have to do manually.
I want to offer another approach based on my comment to your question.
In the below gif, you will see that the 'Create Form' does not become enabled until all the necessary information is provided. You don't see it in the gif so much, but each entry that requires validation also has it behind the scenes in code.
The essential code behind that action is this:
Sub checkFields()
Select Case True
Case Len(Me.formTitleLine1) = 0, Len(Me.formPrefix) = 0, Len(Me.formNumber) = 0, Len(Me.formProduct) = 0, Len(Me.formEditionMonth) = 0, Len(Me.formEditionYear) = 0
Me.createForm.Enabled = False
Case Else
Me.createForm.Enabled = True
End Select
End Sub
And it's called on the afterUpdate event of each relevant box:
Private Sub formEditionYear_AfterUpdate()
checkFields
End Sub
With one small change to the checkFields sub, you can only show the save button once everything has been filled in correctly. That change would be:
Me.createForm.Visible
instead of
Me.createForm.Enabled

Accessing Microsoft Forms 2.0 Frame Controls in VBA

I found out that the only way to have controls be visible in a Frame in Excel is to add them with right-mouse-click Edit. But when I do this the controls are not listed in VBA.
These are the controls on the worksheet:
The first option button is optToday, the first textbox txtToday, the second option button optDate, the second textbox txtDate. The frame is groupDate, the button cmdGetWeek, the third textbox is txtWeekofMonth.
But this is all that comes up in VBA:
I am looking to call a function to calculate week of month when the user clicks on the button. If the user selected today this is the date that will be sent to the function. If the user selected a different date that will will be sent instead.
What I have so far for the code is this:
Private Sub cmdGetWeek_Click()
Dim selectedDate As Date
Dim calcWeekNum
If (optToday.Value = True) Then
selectedDate = txtToday.Value
Else:
selectedDate = txtDate.Value
End If
MsgBox ("Selected: " & selectedDate)
calcWeekNum = WeekOfMonth(selectedDate) End Sub
I get a Run-Time Error '424' for "If (optToday.Value = True) Then".
What is the correct way of accessing the frame controls?
It's unclear whether you added a Form Frame or an ActiveX Frame.
Form Frames are insertable, by default, from the Insert menu:
In order to be able to handle control events in VBA, you need to use the ActiveX form of the Frame control... But by default, the Frame ActiveX control isn't visible on the Insert menu. You'll need to press the More Controls button:
And then choose Microsoft Forms 2.0 Frame Control from the list of controls:
You'll then need to ensure that you add the ActiveX form of the Option Buttons and other controls... All of the controls (and their events), including the Frame and the Option Buttons will then appear in the Worksheet's event drop-down.

Multipage tabs visible, but inactive

I have a user form with multipage. I would like to have the tabs of a multipage visible on top, so the user knows on which page he is and how many there are left. But I would like to disable the possibility to jump between the tabs by pressing on the tab name. Instead only next and back buttons would be available to navigate between the pages. Is it possible just by using the properties, or do I have to write the code for the mulipage change?
create form with one multipage control
then add this code ... click form background to see result
Private Sub UserForm_Click()
If UserForm1.MultiPage1.Pages(0).Enabled Then
UserForm1.MultiPage1.Pages(1).Enabled = True ' must always have at least one enabled
UserForm1.MultiPage1.Pages(0).Enabled = False ' otherwise it looks bad
Else
UserForm1.MultiPage1.Pages(0).Enabled = True ' reverse statements, and you will see
UserForm1.MultiPage1.Pages(1).Enabled = False
End If
End Sub

Excel VBA Calling the Calendar via Command Button in a form

I have just added in Calendar 12.0 from the tools > Additional Controls. Calendar works fine and I have it spitting the date out to the right cells. What I would like, however, is to really make the calendar visible from a command button as my form contains a bunch of fields and I don't want to bog up the form with this calendar. I have tried Calendar1.show but the .show isn't an option.
So ultimately I need a command button to show the calendar, allow the user to select (I have that) and then close the calendar. Any help? I thank you in advance!!
bdubb
In this snippet, CommandButton1 is from the ActiveX controls, not the form controls. It requires that you click the button to show the calendar (which pops up next to the button you clicked), and click the button again to hide the calendar.
Private Sub CommandButton1_Click()
If Not Calendar1.Visible Then
Calendar1.LinkedCell = "A1"
Calendar1.Top = Sheet1.CommandButton1.Top
Calendar1.Left = Sheet1.CommandButton1.Left + Sheet1.CommandButton1.Width + 1
Calendar1.Visible = True
Else
Calendar1.Visible = False
End If
End Sub
Obviously, different buttons would require different linked cells, but it does mean that you could have a single calendar control that it displyed by multiple buttons (if that is what you want).
Unfortunately, it would appear that you cannot hide the control while any of its events are firing (e.g AfterUpdate). It just doesn't want to disappear!!
Hide/Close a calendar control still not works (new year 2015 = almost four years later) but I think I found a workaround to hide the control after firing events.
I have a Calendar1_AfterUpdate(), which launches before Calendar1_Click(). Code is placed directly in a worksheet and NOT in a module.
Private Sub Calendar1_AfterUpdate()
Range("a1") = Me.Calendar1.Value
' Next two lines does not work within AfterUpdate
' When running step by step it seems to work but the control is
' visible when End Sub has run
Me.Calendar1.Visible = True
Me.Calendar1.Visible = False
End Sub
To that I simply added
Private Sub Calendar1_Click()
Me.Calendar1.Visible = True
Me.Calendar1.Visible = False
End Sub
Please note that the control for some reason must be made visible before hiding.
Why it does not work directly in Calendar1_AfterUpdate() is a mystery to me.
Next problem is to hide the control when I remove the mouse. Mouse-events seems to be impossible in a calendar control ...

Resources