VBA:范围方法失败

我正在编写一个代码来select一个范围内的“打开”工作簿的所有数据条目,但编译器在最后一行给出错误(设置范围rng)

Dim wb As Workbook Set wb = Workbooks.Open(Range("C2") & Range("C3")) 'here Range("C2") & Range("C3") contains the location of the file's path Dim ws As Worksheet Set ws = wb.ActiveSheet Dim frow As Long frow = ws.Range("A" & Rows.count).End(xlUp).Row Dim rng As Range Dim frow1 As Long frow1 = ws.Cells(1, Columns.count).End(xlToLeft).Column Set rng = wb.ActiveSheet.Range(Cells(1, 1), Cells(frow, frow1)) 

尝试:

 Dim frow As Long frow = ws.Range("A" & ws.Rows.count).End(xlUp).Row Dim rng As Range Dim fcol As Long fcol = ws.Cells(1, ws.Columns.count).End(xlToLeft).Column Set rng = ws.Range(ws.Cells(1, 1), ws.Cells(frow, fcol)) 

请记住,如果您正在使用设置工作表,您必须在所有范围对象中引用它