Opening URL from VBA (1 Viewer)

SaskiaHe

New member
Local time
Today, 15:49
Joined
Jan 12, 2010
Messages
2
Hi,

I'm trying to open an URL from Visual Basic and the code below works fine:

Sub OpenURL(urlName)
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate urlName
Set ie = Nothing
end sub

However, when I'm executing the code, it is giving a security warning and asking me to open or save the URL. Is there a way to get rid of this question and always open the link directly ?

Kindest regards,

Saskia
 

Zigzag

Registered User.
Local time
Today, 23:49
Joined
Aug 19, 2007
Messages
386
Have you tried

APPLICATION.FollowHyperlink (URL), "", False
 

SaskiaHe

New member
Local time
Today, 15:49
Joined
Jan 12, 2010
Messages
2
That doesn't make a difference.

I noticed, it happens only when I try to open an internet shortcut. Opening an external link or opening the full link does not show the security warning.
However, in my application I don't have the full link available.

Is there any way in VBA to get this full link from the url ?
Or is there a way to pass this security warning.

Saskia
 

Simon_MT

Registered User.
Local time
Today, 23:49
Joined
Feb 26, 2007
Messages
2,177
I use this code that uses QueryStrings and tied to Form Data (Artist). I don't care which browser is used.

The full URL is made up into a String first as Access 2007 was getting picky about the construction of the QueryString.

Code:
Function Web_ArtistsBiogsPlain()
    With CodeContextObject
        Dim WebLink As String
        WebLink = GetWebPath & "Artists_Biographies.aspx?Artist=" & .[Artist] & "&BStyle=P" & ""
        Application.FollowHyperlink WebLink, , True
        HideWebToolBar
    End With
End Function

Simon
 

gunslingor

Registered User.
Local time
Today, 15:49
Joined
Jan 13, 2009
Messages
50
I realize this thread is old, but I've been having similar problems and no posts referenced the solution I happen to stumble upon... so here it is for use by others:

Private Sub Patch_ID_Click()
Dim WebLink As String
WebLink = Application.HyperlinkPart(Me.Patch_URL, acAddress)
Debug.Print WebLink
Application.FollowHyperlink WebLink, , True
End Sub

The reason I did this was because my hyperlink field was too log in datasheet view. So instead, I use the onclick event of another identifier field.... that event pulls out just the hyperlink from the hyperlink field and opens it. The hashtags/pound signs aren't an issue anymore, originally like this:

Private Sub Patch_ID_Click()
Dim WebLink As String
WebLink = Me.Patch_URL
Debug.Print WebLink
Application.FollowHyperlink WebLink, , True
End Sub

but hyperlink had '#' before and after.
 

omnibaer

New member
Local time
Today, 15:49
Joined
Oct 29, 2014
Messages
8
I realize this is a veeeerrrry old post now, but here's an "easy" solution to this:

Private Const SW_SHOWNORMAL = 1

#If VBA7 Then
Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As LongPtr, _
ByVal lpszOp As String, _
ByVal lpszFile As String, _
ByVal lpszParams As String, _
ByVal LpszDir As String, _
ByVal FsShowCmd As Long _
) As Long
#Else
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal lpszOp As String, _
ByVal lpszFile As String, _
ByVal lpszParams As String, _
ByVal LpszDir As String, _
ByVal FsShowCmd As Long _
) As Long
#End If

Public Function Open_URL(URL As String) As Boolean
#If VBA7 Then
Dim Scr_hDC As LongPtr
#Else
Dim Scr_hDC As Long
#End If
Dim procID As Long

On Error Resume Next

Scr_hDC = GetDesktopWindow()

If Scr_hDC = 0 Then Exit Function

procID = ShellExecute(Scr_hDC, _
"Open", _
URL, _
"", _
"", _
SW_SHOWNORMAL)

If procID > 0 Then
Open_URL = True
Else
Open_URL = False
End If
End Function

Sometimes the best solutions are the most complicated, annoying ones. ;)
 

Users who are viewing this thread

Top Bottom