excel超链接打开文件夹
You can use Excel hyperlinks to navigate through a workbook, go to web pages, open other Excel files, and even open PDF files. However, if you try to use an Excel hyperlink to run command files, you’ll run into problems. Until now! Here’s how J.Woolley uses hyperlinks, with a background macro, to avoid those problems – and a other problems too. He also found a strange hyperlink bug.
您可以使用Excel超链接浏览工作簿,转到网页,打开其他Excel文件,甚至打开PDF文件。 但是,如果您尝试使用Excel超链接来运行命令文件,则会遇到问题。 到现在! 这就是J.Woolley如何使用带有背景宏的超链接来避免这些问题以及其他问题。 他还发现了一个奇怪的超链接错误。
超链接命令文件问题 (Hyperlink Command File Problems)
Websites and Excel files open nicely (usually), if you click a hyperlink in a worksheet. With command files, you’ll run into issues, such as:
如果您单击工作表中的超链接,则网站和Excel文件将正常打开(通常)。 使用命令文件,您会遇到一些问题,例如:
- Dialog boxes appear, and you have to click an OK or Cancel button
出现对话框,您必须单击“确定”或“取消”按钮
- You can’t add command line arguments in the hyperlink
您不能在超链接中添加命令行参数
- Shell window flashes with a long or complex script file (cmd or vbs)
Shell窗口使用长脚本或复杂脚本文件(cmd或vbs)闪烁
地址错误问题 (Bad Address Problems)
Even with file types that should open from a hyperlink, you’ll see an error message if there is a problem with the address. Here’s what appears if I misspell Contextures in a cell, and then click the link that is automatically created.
即使应该从超链接打开的文件类型,如果地址有问题,您也会看到错误消息。 如果我在单元格中拼写了Contextures,然后单击自动创建的链接,则会出现以下内容。
The message says, “Unable to open http://www.contexturs.com/. Cannot locate the Internet server or proxy server.’
消息显示,“无法打开http://www.contexturs.com/。无法找到Internet服务器或代理服务器。”
超链接到打开的命令文件 (Hyperlink to Open Command Files)
To overcome these problems, J. Woolley created a technique that runs command files, by launching a macro when specific types of hyperlinks are clicked.
为了克服这些问题,J。Woolley通过单击特定类型的超链接时启动宏来创建一种运行命令文件的技术。
- If the cell contains text that looks like “RUN::COMMAND”, then a macro named ProcessRunCommand runs.
如果该单元格包含看起来像“ RUN :: COMMAND”的文本,则将运行一个名为ProcessRunCommand的宏。
- Normal hyperlinks, without that text, are not affected.
没有该文本的普通超链接不会受到影响。
To set up one of these special hyperlinks:
要设置这些特殊超链接之一:
Insert a hyperlink in a cell (this doesn’t work for the HYPERLINK function)
在单元格中插入超链接(这不适用于HYPERLINK函数 )
- Change its text to include the RUN::COMMAND text
更改其文本以包含RUN :: COMMAND文本
- Add the worksheet code and ProcessRunCommand to your workbook
将工作表代码和ProcessRunCommand添加到您的工作簿
示例脚本超链接 (Sample Hyperlink for Script)
For example, this hyperlink is set up to run a script file, stored in the same folder as the Excel file.
例如,此超链接设置为运行脚本文件,该脚本文件与Excel文件存储在同一文件夹中。
When you click the link, the Excel macro runs the script runs, and opens a window where you enter text
当您单击链接时,Excel宏将运行脚本,并打开一个窗口,您可以在其中输入文本
Next, it shows a message with the text that you entered.
接下来,它显示一条消息,其中包含您输入的文本。
超链接错误 (Hyperlink Bug)
While working on this technique, J. Wooley found an odd Hyperlink bug. Or maybe it’s a feature. Here’s how you can recreate it:
在研究这项技术时,J。Wooley发现了一个奇怪的超链接错误。 也许这是一个功能。 重新创建的方法如下:
- Insert a hyperlink in a worksheet cell
在工作表单元格中插入超链接
- Copy the cell with the hyperlink
复制带有超链接的单元格
- Select a few other cells, and paste the hyperlink
选择其他几个单元格,然后粘贴超链接
- Click on any of the cells where the hyperlink was pasted – the link should work correctly
单击粘贴超链接的任何单元格–链接应正常工作
Everything looks okay, but the next step shows the problem
一切看起来还不错,但是下一步显示了问题
- Delete any one of those pasted cells
删除任何一个粘贴的单元格
- Try to click on one of the remaining hyperlinks
尝试单击剩余的超链接之一
You can’t click on them — the hyperlink is removed from all of the other cells where the hyperlink was pasted!
您无法单击它们-超级链接将从粘贴超级链接的所有其他单元格中删除!
Instead of a pointing hand, the mouse pointer is a white plus sign.
鼠标指针不是白色的指针,而是白色的加号。
避免超链接错误 (Avoiding the Hyperlink Bug)
All the pasted cells were treated as a single Hyperlink.Range.Address, instead of having one address per cell. You can see that if you run the following code on that worksheet.
所有粘贴的单元都被视为单个Hyperlink.Range.Address,而不是每个单元具有一个地址。 您可以看到,如果在该工作表上运行以下代码。
I was able to avoid the problem by also copying a blank cell beside the original hyperlink cell, and pasting that too.
我还可以通过在原始超链接单元格旁边复制一个空白单元格并将其粘贴来避免该问题。
J. Woolley has a few other suggestions for avoiding the problem, and those are in the PDF file that’s in the download file.
J. Woolley还有其他一些避免该问题的建议,这些建议都在下载文件中的PDF文件中。
获取超链接示例文件 (Get the Hyperlink Sample Files)
Download the sample file from my Contextures website, to get all the details on how this technique works. On the Sample Files page, go to the UserForms and VBA section. Look for UF0038 – Hyperlinks Run Command Files
从我的Contextures网站下载示例文件,以获取有关此技术如何工作的所有详细信息。 在“ 示例文件”页面上 ,转到“用户窗体和VBA”部分。 寻找UF0038 –超链接运行命令文件
Unblock the zipped file (see notes below), then unzip the file, and keep all the files in the same folder, for testing.
解压缩该压缩文件(请参阅下面的注释),然后解压缩该文件,并将所有文件保留在同一文件夹中以进行测试。
The zipped folder contains:
压缩文件夹包含:
- Excel workbook with the macros, and hyperlinks for testing.
具有宏的Excel工作簿,以及用于测试的超链接。
- Command file for testing
测试命令文件
- Script file for testing
用于测试的脚本文件
- PDF file with notes on the hyperlink bug
带有超链接错误注释的PDF文件
- PDF file with setup details and notes
包含设置详细信息和注释的PDF文件
- BAS file with the ProcessRunCommand macro
具有ProcessRunCommand宏的BAS文件
取消阻止文件 (Unblock the Files)
Before you unzip the downloaded folder, be sure to unblock the zipped file in Windows Explorer.
解压缩下载的文件夹之前 ,请确保在Windows资源管理器中解压缩压缩文件。
- Right-click the zipped file, then click Properties
右键单击压缩文件,然后单击“属性”。
Add a check mark in the Unblock box, near the bottom of the Properties window.
在“属性”窗口底部附近的“ 取消阻止”框中添加一个复选标记。
- Click OK, to close the Properties window
单击确定,关闭“属性”窗口
- The, unzip the folder, and all the files inside will be unblocked, and ready to use.
将文件夹解压缩,其中的所有文件将被解除阻止并可以使用。
评论或问题 (Comments or Questions)
If you have questions or comments about the Run Command Files technique, contact J. Woolley.
如果您对“运行命令文件”技术有疑问或意见,请联系J. Woolley 。
翻译自: https://contexturesblog.com/archives/2017/09/14/excel-hyperlinks-run-command-files/
excel超链接打开文件夹