如何解决Excel Applescript选择列
我正在尝试制作一个Excel(v16.4)苹果脚本,该脚本删除前几行,然后移至最后一列,其标题为“注释”,并将该文本复制到F列中。
第一部分工作正常,但我无法为我选择该列。我遇到的问题是“注释”列在每个文件的不同位置。我可以进入Notes列,但是我尝试过的任何方法都无法从这一点上选择excel来选择整个列,我只收到错误消息“您尝试访问的对象不存在”。我在下面复制了我的最后2个Applescript;我尝试了几种选择,但没有运气。
版本1
-- find "Notes" column
set lastRow to count of rows of used range of active sheet
set theEnd to get end range "A1" direction toward the right
select theEnd
set x to (get column entry index of the active cell)
select column x
版本2
--Find "Notes" column
set findNotes to "Notes"
set searchRange to range ("A1:AN1")
set foundColumn to find searchRange what findNotes with match case
goto reference foundColumn
--Duplicate Column
set addr to get address (column 1 of selection)
set addr to text 2 thru 2 of addr
-- e.g range $H:$H"
set myWantedRange to "$" & addr & ":$" & addr
set src to range myWantedRange of sheet 1 of workbook "Workbook1"
set dst to range column 6 of sheet 1 of workbook "Workbook1"
copy range src destination dst
解决方法
试试这个:
基本上,它获取所用范围的最后一列并检查其第一个单元格是否为“注释”。如果是,则复制该列单元格的值,然后将它们放入使用范围的第6列的相应单元格中。一切都以使用范围为界。
tell application "Microsoft Excel"
tell worksheet 1 of workbook 1
with timeout of 20 seconds
set cour to columns of used range
set lCol to last item of cour
set fCol to item 6 of cour
if value of cell 1 of lCol is "Notes" then
set lcv to value of lCol
set value of fCol to lcv
end if
end timeout
end tell
end tell
cour
是有限的列列表。它的最后一列 (lCol) 将以这种方式引用:
column "$J$1:$J$30" of application "Microsoft Excel"
然后只需设置 F 列的值即可。我使用的是 Excel 2011,但这里应该不是问题。超时行只是为了在您尝试处理整个列时停止程序。
我认为您不需要选择任何内容,但如果您想选择其中任何一列(在使用范围内),只需使用以下任一列:
select fcol
select lcol
select column "$J$1:$J$30"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。