answerSeeker
answerSeeker

Reputation: 2772

Open links using vba without FollowHyperlink

On my vba procedure, I have ActiveWorkbook.FollowHyperlink Address:=link but "Link" is often too big for the function to use because "link" could hold string values as big as a small paragraph and this causes me to have a run-time error. It works with links with smaller string size but the with the big ones, if fails with this exact error below

error

Is there another way to open links using vba that could handle big urls?

Upvotes: 0

Views: 567

Answers (1)

FaneDuru
FaneDuru

Reputation: 42236

Please, try using API. It should accept the URL maximum string length (2048).

  1. Copy the next code on top of a standard module (in the declarations area):
Option Explicit

Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
                            ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
                            ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
  1. Copy the next code in the standard module where the API function has been copied:
Sub testOpenURL
   ShellExecute 0&, vbNullString, "http://www.your big string representing URL", vbNullString, vbNullString, 5
End Sub

Upvotes: 1

Related Questions