开发者

AppleScript, Microsoft Excel, and Hyperlink Enabling

开发者 https://www.devze.com 2023-03-30 07:04 出处:网络
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?

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?

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):

开发者_运维百科
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! (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.

For comparison, here's a working Excel Macro (using a selection).

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). 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

n.b.: I have no idea if this is "proper" AppleScript, but I figure it's a start. Feel free to offer improvements, by all means!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号