Download dialog Box IE - vba

I have use this code
Controlling IE11 "Do you want to Open/Save" dialogue window buttons in VBA
But I get the error
"user defined type not defined"
on
Dim o As IUIAutomation
Someone knows how can I fix it?

I guess you have to add a project reference to the UI Automation library. At least I could reproduce your error and fix it by adding the reference.

Add it using code
Public Sub AddReference()
ThisWorkbook.VBProject.References.AddFromFile
"C:\Windows\System32\UIAutomationCore.dll"
End Sub
and goto excel>>option>>Trust Center>>Trust Center Setting>>Macro setting and check on the Trust access to the VBA project object model

Related

How to run code in a custom appointment tab?

I'm trying to write an extension to my Outlook calendar - More specifically the appointment module. (Form designer)
I have a button in my designer, that I want to write some simple code around.
Sub CommandButton1_Click()
msgbox "Hello World"
End Sub
The above code is put into the code editor that appears when I press "View code". Nothing happens.
How do I get a commandbutton to trigger a simple alert in the Outlook form designer?
Custom form script is now disabled by default. You can see more details for the known issue and you can re-enable it as the following link suggests.
You can read more about that in the Custom Form Security Changes article

Word VBA: Run-time error '-2147467259 (80004005)' when calling FileDialog.Execute

Using Office365 under Windows 10.
I am trying to invoke the Save dialog programmatically and then save the open document.
Minimal testcase:
Private Sub TestSave()
If Application.FileDialog(msoFileDialogSaveAs).Show Then
Application.FileDialog(msoFileDialogSaveAs).Execute
End If
End Sub
(For the real code, I am programmatically setting the default filename and filter, but these aren't needed to show the problem.)
However, on the call to .Execute, I get an error popup:
Run-time error '-2147467259 (80004005)'
Command failed
What does this mean? How do I fix it? (The Help button in the error dialog doesn't lead to any page that explains the error.)
This seems to be happening regardless of what folder I try to save to.

excel vba remove controls

I currently have a form with a couple of buttons, text boxes and a AcroPDF. AcroPDF is an additional control I have added to my toolbox and I get it from "Adobe PDF Reader".
This macro is being used on various computers and I have found out that, for some reason, the macro does not work on all computers. But when I delete the AcroPDF control from the form, it works for all computers. For the computers that do get an error, it happens when I first open the file I automatically get an error msg and the form does not automatically show up (like how I programmed it to).
Is there a way I can program this into my "Thisworkbook.open" so that if there is an error, I can somehow delete or disable this additional control? something similar to how you are able to turn on and off references? (see below)
ThisWorkbook.VBProject.References.AddFromFile ("libraryName")
UPDATED: the error message I get from the computers that don't work is the following:
system error &H80004005 (-2147467259). unspecified error
Thanks.
UserForm.Controls.Remove -- but this only works for controls added at runtime (dynamically). You cannot use the Remove method on a control that was added from the Designer.
Probably you need to reverse this logic, and only add the control when the reference exists on the user's machine.
Dim ctrl
If Len(Dir("libraryname")) <> 0 Then
Set ctrl = UserForm1.Controls.Add ...
End If
You would also then want to use the Remove method when closing the form, that way the form remains in a state that could be opened on either computer.
HOWEVER, the error message you get on the other machines may shed additional light on the source of the problem. Depending on what the error is, there may be other solutions that don't involve removing the control.
If you don't mind creating a duplicate form without the AcroPDF control you might be able to use labels and the GoTo statement.
Sub Workbook_Open()
' do stuff
On Error GoTo AcroPDFError
ThisWorkbook.VBProject.References.AddFromFile ("libraryName")
' load your form with the AcroPDF control here.
Continue:
On Error GoTo 0
' the rest of your Workbook_Open sub is here
Exit Sub
AcroPDFError:
' load your form without the AcroPDF control here.
GoTo Continue
End Sub

Visual Basic run webbrowser with java

I'm trying to make a Runescape Client in Visual Basic, but when I run http://www.runescape.com/game in a web browser it tells me to install java
It brings up an error saying:
*An error has occurred in the script on this page.
line: 48
Char: 325
Error: Expected ')'
code: 0
URL: http://www.runescape.com/game
Do you want to continue running the scripts on this page?
(Yes/No)*
I need a way to run Runescape inside a visual basic Application.
Is there any way to add java to the web browser?
Any help would be appreciated :)
This is due to a JS error, the easiest fix is to input in the Form load,
WebBrowser1.ScriptErrorsSuppressed = True
Hopefully that works?
It looks like you are getting this error, which is a JavaScript error on the page, not a Java error on your machine.
To resolve, you need to clear the "Display a notification about every script error" check box in the Advanced section of the Internet Options menu. Here's a lengthy article on Microsoft Support describing how to access and change the Internet Options via VB.Net.
The relevant code from that page to access the Internet Options:
Public Sub InternetOptions()
Dim cmdt As IOleCommandTarget
Dim o As Object
Try
cmdt = CType(GetDocument(), IOleCommandTarget)
cmdt.Exec(cmdGUID, Convert.ToUInt32(MiscCommandTarget.Options), _
Convert.ToUInt32(SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT), o, o)
Catch
' NOTE: Due to the way this CMDID is handled inside of Internet Explorer,
' this Catch block will always fire, even though the dialog
' and its operations completed successfully. Suppressing this
' error will cause no harm to your host.
End Try
End Sub
just set the webbrowser ScriptErrorsSuppressed property to true and thats all

Excel VBA hiding custom ribbon tab

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