2016-08-13 36 views
-2

在打開此工作簿時,將運行以下腳本,該腳本會寫入一個公式以創建指向多個工作簿的鏈接。每個工作簿寫入3列即工作簿1寫入到A,B和C以及工作簿2寫入d,E,F等。加速此vba腳本

WBNAME = "=IF(AND('\\insurance\it\FileData\Computers\Release Note\[Aliens.xlsm]iForms'!A2<>"""",'\\insurance\it\FileData\Computers\Release Note\[Aliens.xlsm]iForms'!E2=""""),'\\insurance\it\FileData\Computers\Release Note\[Aliens.xlsm]iForms'!A2,"""")" 
Worksheets("All Release Items").Range("A2:A100").Value = WBNAME 
WBNAME2 = "=IF(AND('\\insurance\it\FileData\Computers\Release Note\[Aliens.xlsm]iForms'!A2<>"""",'\\insurance\it\FileData\Computers\Release Note\[Aliens.xlsm]iForms'!D2<>"""",'\\insurance\it\FileData\Computers\Release Note\[Aliens.xlsm]iForms'!E2=""""),'\\insurance\it\FileData\Computers\Release Note\[Aliens.xlsm]iForms'!D2,"""")" 
Worksheets("All Release Items").Range("B2:B100").Value = WBNAME2 
WBNAME3 = "=IF('\\insurance\it\FileData\Computers\Release Note\[Aliens.xlsm]All Release Items'!A2<>"""",'\\insurance\it\FileData\Computers\Release Note\[Aliens.xlsm]All Release Items'!A1,"""")" 
Worksheets("All Release Items").Range("C2:C100").Value = WBNAME3 

目前有12個工作簿所有.XLSM和位於同一文件內路徑。 請幫忙

回答

0

問題的一部分是它需要將公式更新爲未在應用程序會話中打開的引用工作簿。如果打開工作簿,則可能會更快,然後輸入公式。

您可以通過將計算模式設置爲手動(在「公式」功能區頁面的「計算」部分或Application.Calculation = xlCalculationManual),然後運行宏,然後「立即計算」(再次在功能區上,或F9),並看看需要多長時間。比較運行它的時間就像那些被引用的工作簿處於打開狀態和關閉狀態時那樣。我認爲你會發現宏需要很短的時間來添加公式,但是計算需要很長時間,因爲工作簿已關閉。

如果是這樣的話,重寫它以在計算之前打開工作簿。

另外,如果需要像這樣引用數據,您可能需要考慮將數據放入數據庫中。