+ Reply to Thread
Results 1 to 9 of 9

MAC: Using VBA to open an HTML file in default browser

  1. #1
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    MAC: Using VBA to open an HTML file in default browser

    I have a workbook that we use on both Windows and Mac workstations. One piece of code creates an HTML file then opens that HTML file in the default browser. The section of code that launches the HTML file on Windows is below, but when this is run on a Mac the code sorta runs within a new Excel worksheet. The value strFName gets set to "C:\Users\user\AppData\Local\Temp\GoogleMaps.HTML" on Windows and "Machintosh HD:Users:user:Documents:GoogleMaps.html" on the Mac. I can confirm that manually opening the file works on the Mac, but getting it to launch outside of an Excel worksheet is just not happening.

    Any thoughts about what sort of code would work in this situation? I already use an If/Then/Else function to identify the default file locations, I'm open to doing it for different launching solutions if that gets the job done.

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Re: MAC: Using VBA to open an HTML file in default browser

    any other thoughts?

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: MAC: Using VBA to open an HTML file in default browser

    I'm assuming that was a typo of Macintosh (machintosh).

    Just a thought but have you tried leaving out the user, i.e.

    "Macintosh HD:Users:Documents:GoogleMaps.html"
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Re: MAC: Using VBA to open an HTML file in default browser

    Yes, a typo, thanks.

    I've tried taking user out of the string but that causes an Out of Memory error. It seems that the ActiveWorkbook.FollowHyperlink function only opens a URL, and will not launch the browser with the HTML file.

    I'm not familiar enough with the differences between Mac VBA and Windows VBA but maybe there's a way to execute an external program and that that will open a browser with the HTML file, similar to double-clicking the HTML. I've tried a few variations of the Mac VBA Shell function with no success. I'm getting various errors as if the syntax is incorrect. Any ideas what the Shell or other formula syntax might be to launch an HTML file from Excel?
    Last edited by JimDandy; 08-02-2017 at 04:44 PM.

  5. #5
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Re: MAC: Using VBA to open an HTML file in default browser

    Does anyone know how to launch Safari from Excel VBA and open the HTML file? If I open the file from Finder it launches the browser and the address is "file:///Users/username/Documents/GoogleMap.html". I've tried variations on the use of Shell but I get either "path not found" or "invalid argument." I cannot seem to get the proper syntax.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: MAC: Using VBA to open an HTML file in default browser

    For 2016 you should use posix paths with / rather than : in them.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  7. #7
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Re: MAC: Using VBA to open an HTML file in default browser

    Thank you....On the Windows platform I'm using Office 2016 but on the Mac it's 2011. The issue isn't the formatting of the path as much as it is that Excel on the Mac does not appear to allow launching another program from VBA. My issue is that I build an HTML file from data within the Excel worksheet, and I need to cause the HTML file to be executed outside of Excel. The file is created properly, and executing the HTML file from Finder confirms this but getting Excel Mac to load it is the goal. Excel only seems to be able to open the HTML inside a new Worksheet. If I only needed to open the default browser with a link, that seems to work fine, but I need the entire HTML file to open in the browser, not Excel.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: MAC: Using VBA to open an HTML file in default browser

    I imagine you may need to use MacScript to run a browser and open the HTML file that way.

  9. #9
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Re: MAC: Using VBA to open an HTML file in default browser

    Thank you!

    MacScript/AppleScript was the final solution. In Excel I used some MacScript commands to capture the Mac's directory structure and to run an AppleScript routine to actually launch the HTML. Although I didn't test it otherwise, I read that the one caveat that the Mac requires is that the com.microsoft.Excel directory be created in the ~/Library/Application Scripts directory, if not already there, and used to store the AppleScript script files. My guess is that the Mac only allows scripts from Excel to be launched from this single location.

    The two separate sections of Excel VBA code used to capture the Mac directory (or Windows) and then to launch the AppleScript script file (or on Windows it will launch the HTML directly):
    Please Login or Register  to view this content.
    This is the AppleScript file's code (LaunchMaps.scpt), which launches Safari if not already loaded, brings it to the foreground, then loads the HTML file:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA to open list of hyperlinks in non-default browser?
    By Lycn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2015, 12:08 PM
  2. Open link from spreadsheet into user's default browser
    By Steve_123 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2015, 10:42 AM
  3. Open hyperlink with Firefox when IE is default browser?
    By Haze1434 in forum Excel General
    Replies: 2
    Last Post: 03-04-2014, 10:16 AM
  4. Some hyperlinks don't open in default browser
    By biznez1 in forum Excel General
    Replies: 0
    Last Post: 05-17-2013, 02:14 PM
  5. Macro to save workbook as html then open it in a browser.
    By brent_milne in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-25-2012, 03:53 PM
  6. Open Multiple Hyperlinks in Default Browser
    By thelukeeffect in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-29-2011, 02:20 PM
  7. Replies: 1
    Last Post: 02-23-2010, 05:36 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1