Consulting

Results 1 to 8 of 8

Thread: Opening URL with Fragment Identifier from VBA Excel

  1. #1
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    5
    Location

    Question Opening URL with Fragment Identifier from VBA Excel

    By FollowHyperlink I can open a web page with a Fragement Identifier (i.e. with an ending part after a '#' sign pointing to a specific portion of the web page).
    Works lika a charm.

    However if I try the same thing for a file URL for example the same web page stored as a file on C:\ it does not work. The Fragment identifier is completely ignored. My default browser opens the page, but ignores the fragment identifier.

    Is this a known bug/limitation?
    Is there some work-around?

    Here is a code snippet for illustration. My default browser (both IE and Chrome) ignores myFragment. I don't think it is passed on at all:
    Option Explicit
    Private Sub CommandButton1_Click()
      Dim aFile As String
      aFile = "C:/myFile.html#myFragment"
      ActiveWorkbook.FollowHyperlink aFile, NewWindow:=True
    End Sub
    Last edited by HeMor; 12-08-2015 at 08:48 AM.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    Check that aFile exits and then add the prefix string "File://" to aFile.

  3. #3
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    5
    Location
    Thanks for your welcome and for your suggestions! Appreciate it!

    However, my problem is not to locate or to open the file in my default browser. That works fine, both with and without a 'File:" prefix (followed by three slashes).
    Problem is that the fragment part (after the '#') is ignored. It does not appear in the browser. Therefore the html file opens at the very top. not at the section I want (specified by the fragment).

    I'm pretty sure this is a VBA Excel problem.
    - I can write the adress with a fragment manually in the browser with the desired result
    - I can open the file from another scripting language (DOORS/DXL) with the desired result.
    - And the fragment works fine if a call a http webpage. (html-wise identical to the file).

  4. #4
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    5
    Location
    I managed to solve my problem by a cmd.exe detour.
    Still annoying though that it does not work directly from VBA!

    For the moment I haven't figured out how to use the default browser, so I explicitly calls Internet Explorer.

    NOTE: The forum doesn't let me post links, so in the code below I had to replace '///' characters with a placeholder. Sorry for that.


    Option Explicit
    Private Sub CommandButton1_Click()
      Dim cmdLine As String
      cmdLine = "start iexplore.exe """File:[Three slashes]C:/myFile.html#myFragment""
      Shell "cmd.exe /c " & cmdLine
    End Sub

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I see now. I have not done that. Have you tried setting it in ExtraInfo?

  6. #6
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    5
    Location
    Yes, I made some unsuccessful attempts using ExtraInfo or SubAdress. In both cases the html file opens, but ExtraInfo and SubAdress seems to be ignored.

    Here is what I tried:

    ActiveWorkbook.FollowHyperlink aFile, NewWindow:=True, ExtraInfo:="myFragment"

  7. #7
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I don't have time to play with that right now.

    I would expect that a call to your web browser and then pass your string as a command line parameter value in a Shell() might work.

  8. #8
    VBAX Newbie
    Joined
    Dec 2015
    Posts
    5
    Location
    Thanks, yes that's what I did (see 4th post in the thread from earlier today)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •