我有一個腳本從Excel(Mac Excel'04)電子表格中提取信息,並通過本地數據庫進行處理。我的問題(這是暫時的,等待專用腳本機w/Excel'08)是我需要在Excel中處理另一個電子表格時。我想確保AppleScript繼續從正確的電子表格中讀取數據。告訴AppleScript轉到Excel中的特定窗口
有沒有辦法將引用傳遞給AppleScript中的特定Excel文件,而不是一般地告訴應用程序?或者可能只是參考電子表格而不必打開它...?
我有一個腳本從Excel(Mac Excel'04)電子表格中提取信息,並通過本地數據庫進行處理。我的問題(這是暫時的,等待專用腳本機w/Excel'08)是我需要在Excel中處理另一個電子表格時。我想確保AppleScript繼續從正確的電子表格中讀取數據。告訴AppleScript轉到Excel中的特定窗口
有沒有辦法將引用傳遞給AppleScript中的特定Excel文件,而不是一般地告訴應用程序?或者可能只是參考電子表格而不必打開它...?
如果我理解正確,那麼您希望啓動一個腳本,該腳本在您處理另一個工作簿時適用於給定的工作簿。
下面的結構應該做的伎倆:
tell application "Microsoft Excel"
set WB_Name to name of workbook 1
tell workbook WB_Name
-- Do your stuff
end tell
end tell
不幸的是,你不能在 「關閉」 的文件工作...
HTH
我在一個單獨的lib定義一勞永逸此功能(等等)
on getActiveBookAndSheet()
try
tell application "Microsoft Excel"
set theBook to workbook (get name of active workbook)
set theSheet to worksheet (get name of active sheet) of theBook
# set theSheet to worksheet (get entry index of active sheet of theBook) -- alternative
return {theBook, theSheet}
end tell
on error
error "Could't find any opened document in Excel."
end try
end getActiveBookAndSheet
將其保存爲ExcelLib。應用在「計算機腳本」文件夾
在涉及到每個Excel的AppleScript的開頭的文件夾「通用」在我加入這一行:
set myExcelLib to load script alias ((path to library folder as string) & "Scripts:Common:ExcelLib.app")
而當談到時間去工作簿和工作表,我只是用這樣的:
set {myBook, mySheet} to myExcelLib's getActiveBookAndSheet()
然後你要在紙張的特定範圍內工作,每次,只要做到這一點是這樣的:
set value of range "A2:F3" of mySheet to "etc." -- for a single line
或
tell mySheet
set value of range "A2:F3" to "etc." -- if you need to perform a whole list of operations
end