3

Is there any way to tell Excel to just pass a URL included in a cell directly to the system browser and don't try and open directly in Excel first?

Here's the detail of the issue:

I have a web app that requires a valid session (a cookie is required). If a request comes in (for a protected page) without a cookie a redirect is issued to the login page.

This web app can generate an Excel spreadsheet with cells that have URLs that point to a resources in the web app. The hope is that one could open the spreadsheet and then click on links in cells to open the pages in their browser (assuming the browser has the cookie).

If I paste one of these URLs into the browser's location bar it works (because the browser will include the cookie). Likewise, if one of these URLs was included in an Email I can click on it, and if currently logged in, will access the resource.

Here's the problem:

But, if I click the link directly in Excel what happens is Excel sends the request, not the browser. Since Excel has no idea about the cookies the browser is holding no cookie is sent.

What happens is Excel request the correct URL. The web app sees the request without the cookie and sends a redirect back to Excel with a Location: header pointing to the login page.

Next, Excel makes another request for the login page.

Finally, the browser is opened (if not already opened) and it makes another request to the login URL.

I assume what's happening is Excel is seeing the login pages is text/html and decides to hand off to the browser, but it's giving the browser the URL provided in the Location:, not the URL that is in the spreadsheet.

Is there a way to configure Excel to not try and open URLs in cells directly?

Running Excel 14.3.5 (Mac 2011).

4

1 回答 1

0

首先,这是我在 Office 2010 的 Windows 副本中使用的。我完全意识到您正在使用 Mac Office,所以这可能需要一些改动......

Public Function OpenSite()

  Dim URL As String

  URL = Worksheets("Sheet1").Range("A1").Value
  Call Shell("C:\Program Files\Internet Explorer\Iexplore.exe " & URL, 1)

End Function

在 windows 环境中,这将使用 Internet Explorer打开其 URL 在Sheet1!A1中的站点

在 StackOverflow 上查看其他地方显示这是在 Mac 环境中使用 URL 调用浏览器的一种可能方法:

Shell("Macintosh HD:Users:brownj:Documents:" & _
                "rnaseq:IGV_2.0.14:igv.sh", vbNormalFocus)

(它似乎不需要先调用“呼叫”命令。)

也许尝试用“{path to your browser}”和 URL替换第一个参数,看看是否能解决问题。如果它有效,只需将其放在Private Sub Workbook_Open下的“ThisWorkbook”对象中,以便在工作表打开时自动执行它。

再一次,很抱歉我无法测试这个......但希望这至少能让你朝着正确的方向前进!

于 2014-02-28T16:13:56.513 回答