简体   繁体   English

AppleScript,Microsoft Excel和超链接启用

[英]AppleScript, Microsoft Excel, and Hyperlink Enabling

There's a question about creating active hyperlinks in Excel without resorting to a macro ... but suppose one does want to create a macro, or rather something in AppleScript? 有一个关于在Excel中创建活动超链接而不求助于宏的问题 ……但是假设有人确实想创建宏,或者想在AppleScript中创建某些东西吗?

I started to plunder the Excel for Mac's AppleScript dictionary ... and, so far, I've got this (presuming column 1 contains row upon row amounting to a URI in each cell, and none are activated): 我开始掠夺Excel for Mac的AppleScript字典...到目前为止,我已经掌握了这一功能(假定第1列包含一行一行,相当于每个单元格中的URI,并且没有被激活):

tell application "Microsoft Excel"
    activate
    make new hyperlink of column 1 at active sheet with properties {address:column 1}
end tell

That almost works ... except each cell ends up being a hyperlink to http://www.microsoft.com/mac/ instead! 几乎可以正常工作……只是每个单元格最终都是指向http://www.microsoft.com/mac/的超链接! (Nice touch there, MSFT. Hehe.) Seriously though, I can't help but think I'm pretty close here, but I'm not sure what I'm missing. (那里很好,MSFT。呵呵。)严重的是,我忍不住想我离这里很近,但是我不确定我缺少什么。

For comparison, here's a working Excel Macro (using a selection). 为了进行比较,这是一个有效的Excel宏(使用选择)。

For Each xCell In Selection
    ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=xCell.Formula
Next xCell

Clues welcome and appreciated! 线索欢迎和赞赏!

I do believe I have it! 我相信我有! Let's say the cells are in column 8 (not counting the header row). 假设单元格位于第8列(不计算标题行)。 You could do something like this. 你可以做这样的事情。

tell application "Microsoft Excel"
    tell (get used range of active sheet)
        repeat with i from 2 to count rows
            set v to value of column 8 of row i
            make new hyperlink at column 8 of row i with properties {address:v}
        end repeat
    end tell
end tell

nb: I have no idea if this is "proper" AppleScript, but I figure it's a start. nb:我不知道这是否是“正确的” AppleScript,但我认为这是一个开始。 Feel free to offer improvements, by all means! 随时提供改进!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM