我有我的分部分試圖指定範圍下面的代碼:VBA類型不匹配的錯誤在Word
'Set xlApp = CreateObject("Excel.Application")
Dim xlApp As Object
Set xlApp = GetObject(, "Excel.Application")
xlApp.Visible = False
xlApp.ScreenUpdating = False
Dim CRsFile As String
Dim CRsMaxRow As Integer
' get the CR list
CRsFile = "CRs.xls"
Set CRsWB = xlApp.Workbooks.Open("C:\Docs\" + CRsFile)
With CRsWB.Worksheets("Sheet1")
.Activate
CRsMaxRow = .Range("A1").CurrentRegion.Rows.Count
Set CRs = .Range("A2:M" & CRsMaxRow)
End With
Dim interestingFiles As Range
' get the files names that we consider interesting to track
Set FilesWB = xlApp.Workbooks.Open("files.xlsx")
With FilesWB.Worksheets("files")
.Activate
Set interestingFiles = .Range("A2:E5")
End With
你有爲什麼我得到一個運行時類型不匹配的任何想法錯誤?
沒有設置'xlApp'我期望一個'424對象required'錯誤,或者如果該文件沒有按」 t存在,那麼'Set FilesWB = ...'會出現錯誤,但是OP表示設置範圍的「不匹配」錯誤。我沒有看到那個'With'塊裏面有什麼不正確的東西。 – 2013-05-05 13:04:17
@DavidZemens你認爲它的'xlApp.Workbooks.Open(「files.xlsx」)是個問題嗎? – Santosh 2013-05-05 13:06:28
在m代碼我把完整的路徑 - 我不覺得舒服在網上... ... – banjo 2013-05-05 13:11:25