我對VBA很陌生,而且一次處理多個工作簿時遇到了一些問題。我有一個功能完整的代碼,基本上只是將數據從一個表單傳輸到另一個表單,並滿足一定的條件。Excel VBA類型不匹配錯誤13
現在我試圖更新代碼從一個工作簿移動到另一個工作簿,因此我已經開始聲明工作簿而不是僅引用表名稱。
現在我收到各種錯誤。
代碼如下。
前(工作)
Option Explicit
Sub TrendDataByDay()
'determine date of data pulled
Dim CurrentDate As String
CurrentDate = Sheets("Daily Pull").Range("B23").Value
(失敗;現在用2個工作簿)後
Option Explicit
Sub TrendDataByDay()
Dim wbDaily, wbHistory As Workbook
'declare daily and history workbooks
Set wbDaily = ActiveWorkbook
Workbooks.Open Filename:="\\Daily Focus Metrics\Focus Metrics History by Facility.xlsm"
Set wbHistory = Application.Workbooks("Focus Metrics History by Facility.xlsm")
'determine date of data pulled
Dim CurrentDate As String
'error here!
CurrentDate = Workbooks(wbDaily).Sheets("Daily Pull").Range("B23").Value
我也試過:
CurrentDate = wbDaily.Sheets("Daily Pull").Range("B23").Value
我需要了解我爲什麼不能只需聲明這些工作簿並以這種方式指定工作表所屬的工作簿。我還想知道在複製或粘貼數據時無需「選擇」每個工作簿的情況下引用和調暗工作簿的理想方法。
'Workbooks(wbDaily).Sheets(「Daily Pull」)。Range(「B23」)。Value' should just'wbDaily.Sheets(「Daily Pull」)。Range(「B23」)。Value' –