How to prevent Error message when using vba follow hyperlink (1 Viewer)

jdraw

Super Moderator
Staff member
Local time
Today, 12:12
Joined
Jan 23, 2006
Messages
14,255
I'm working with a new laptop and a new version of O365. I am trying to loop through a series of hyperlinks(see example below).
I am getting this error when running code in vba .
Code:
Process:
          '  Process the URLs
180       On Error Resume Next
190       sFileName = path & "Pat_out.txt"


200       iFileNum = FreeFile
210       Open sFileName For Input As iFileNum
220       Do Until EOF(iFileNum)
230           Line Input #iFileNum, sBuf
240           Debug.Print "application.followHyperlink   " & sBuf
250           murl = sBuf
260           Application.FollowHyperlink murl
             
270       Loop
         
280       On Error GoTo 0
TestBookmark_Exit:
290       Exit Sub

TestBookmark_Error:

300       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure TestBookmark, line " & Erl & "."
310       GoTo TestBookmark_Exit
End Sub
ErrorMsgFollowHyperlink.PNG


However I don't get the error and the link opens in my Firefox browser when I run it directly from the immediate window.
ImmediateFollowHyperlink.PNG


application.followHyperlink "https://techcommunity.microsoft.com/t5/Access-Blog/bg-p/AccessBlog"
 

CJ_London

Super Moderator
Staff member
Local time
Today, 17:12
Joined
Feb 19, 2013
Messages
14,221
interesting that the back slashes change to forward slashes?

anything to do with assigning sbuff to murl? and then using murl in your followhyperlink?
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:12
Joined
Jan 23, 2006
Messages
14,255
Unsure of the change in backslash direction.
Don't think the sbuf murl is an issue. I used sbuf directly previous attempt and if gave the error. Tried using murl as a different string in case there was an issue using the file buffer directly.

Thanks for responding. Probably a setting for O365 --but I haven't found it. I'm sure others on forums have successfully opened url in browser from within Access/VBA. I recall doing it often before google maps required a paid account.
 

bastanu

AWF VIP
Local time
Today, 09:12
Joined
Apr 13, 2010
Messages
1,172
Looks like you need to edit the registry:https://www.technipages.com/disable-hyperlinks-can-be-harmful-to-your-computer-and-data-message
or switch to use Shell:

Cheers,
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:12
Joined
Jan 23, 2006
Messages
14,255
Thanks Vlad. I'll give it (shell) a try this afternoon.

UPDATE: 12:05PM
Just tried with Shell (based on June's routine in that link) and it worked without error message.(y)
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:12
Joined
Jan 23, 2006
Messages
14,255
Just to finish up. Refreshing bookmark icons after using Firefox sync to move bookmarks
to another laptop.

The code was adjusted to
Code:
Process:
          '  Process the URLs
190       On Error Resume Next
200       sFileName = path & "Pat_out.txt"
          Dim wsShell As Object
t

220       iFileNum = FreeFile
230       Open sFileName For Input As iFileNum
240       Do Until EOF(iFileNum)
250           Line Input #iFileNum, sBuf
260           Debug.Print "application.followHyperlink   " & sBuf
270           murl = sBuf
              ' Application.FollowHyperlink murl

280           wsShell.Run murl  '''''''''''''''' This does not show the security warning
                      
290       Loop
300       Close iFileNum
310       On Error GoTo 0
TestBookmark_Exit:
320       Exit Sub
TestBookmark_Error:

330       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure TestBookmark, line " & Erl & "."
340       GoTo TestBookmark_Exit
End Sub

The rationale for the code:
-working with a new laptop
-did a sync bookmarks, Logins and Passwords (Firefox) from older laptop)
-bookmarks transferred
-EXCEPT the icons (colored) were all transferred as globe symbol
-by opening and closing each bookmark the little colored icons are all restored/refreshed
-there were 1500+ bookmarks(seemed like a job for Access/vba)

I processed the exported bookmarks; copied the related page source; extracted just the urls to a file, ran that file through the code above. Did it in chunks of 40- 80 urls at a time. Sample result.

Recovered bookmarks with icons.PNG
 

bastanu

AWF VIP
Local time
Today, 09:12
Joined
Apr 13, 2010
Messages
1,172
Great news, thanks for the updated code!
:)(y)
Cheers,
 

Users who are viewing this thread

Top Bottom