這是跟我的previous post。我成功是能夠在不同的驅動器上打開工作簿的不同,在一個範圍內的圖片複製數據,然後將其粘貼在ThisWorkbook
我運行到現在。問題是我使用的是.CopyPicture
捕捉單元格值,因此它最終看起來像一堆#N/A Requesting Data...
值。VBA-Excel公式參考 - 計算刷新
我已經使用了一些不同的東西,看看我是否能得到公式複製之前計算,但它似乎是電子表格不會與計算貫徹直到宏不再運行。
我檢查了this post但我不完全確定如何實施if Application.CalculationState is xLdone then loop else wait
。任何幫助?
原始代碼:
Dim BBPic As Workbook
Dim test As Workbook
Set BBPic = Application.Workbooks.Open("\\OtherDrive\Shared\OtherGroup\DailySheet.xlsx")
Set test = ThisWorkbook
BBPic.Sheets("Sheet1").Range("B2:E16").CopyPicture
test.Sheets("Summary").Range("B64").PasteSpecial
第一次嘗試:
Dim BBPic As Workbook
Dim test As Workbook
Set BBPic = Application.Workbooks.Open("\\OtherDrive\Shared\OtherGroup\DailySheet.xlsx")
Set test = ThisWorkbook
BBPic.Sheets("Sheet1").Range("B2:E16").CopyPicture
Application.Wait (Now + TimeValue("0:01:00"))
test.Sheets("Summary").Range("B64").PasteSpecial
Workbooks("DailySheet.xlsx").Close SaveChanges:=False
第二次嘗試:
Dim BBPic As Workbook
Dim test As Workbook
Set BBPic = Application.Workbooks.Open("\\OtherDrive\Shared\OtherGroup\DailySheet.xlsx")
Set test = ThisWorkbook
BBPic.Sheets("Sheet1").Range("B2:E16").CopyPicture
ActiveWorkbook.RefreshAll
test.Sheets("Summary").Range("B64").PasteSpecial
Workbooks("DailySheet.xlsx").Close SaveChanges:=False
最後一次嘗試:
Dim BBPic As Workbook
Dim test As Workbook
Set BBPic = Application.Workbooks.Open("\\OtherDrive\Shared\OtherGroup\DailySheet.xlsx")
Set test = ThisWorkbook
BBPic.Sheets("Sheet1").Range("B2:E16").CopyPicture
ActiveSheet.Calculate
test.Sheets("Summary").Range("B64").PasteSpecial
Workbooks("DailySheet.xlsx").Close SaveChanges:=False
編輯:使用Application.CalculationState = xlDone
Dim BBPic As Workbook
Dim test As Workbook
Set BBPic = Application.Workbooks.Open("\\OtherDrive\Shared\OtherGroup\DailySheet.xlsx")
Set test = ThisWorkbook
BBPic.Sheets("Sheet1").Select
Do Until Application.CalculationState = xlDone: DoEvents: Loop
ActiveSheet.Range("B2:E16").CopyPicture
test.Sheets("Summary").Range("B64").PasteSpecial
Workbooks("DailySheet.xlsx").Close SaveChanges:=False
「如果Application.CalculationState是xLdone然後循環else等待」 基本上意味着'做,直到Application.CalculationState = xlDone:調用DoEvents:Loop'(如果你不知道,冒號':在VBA'分離聲明) – Mikegrann
我在我的第四次嘗試中使用它編輯過,但它似乎沒有工作。 – plankton
你在使用彭博公式嗎? – cyboashu