我想做什么:
A1:A10
&从输入表到工作簿的B1:B10
现在是个大问题:
C1
又名Input sheet.xls
现在我如何告诉VBA读取单元格C1
,以便知道我的输入表名称是什么?
到目前为止,我找到了一个只有在手动更改VBA文件名
时才有效的选项Sub transfervalues()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set wb1 = Workbooks("Input Sheet.xls")
Set ws1 = wb1.Sheets("COPY")
Set wb2 = Workbooks("Workbook.xls")
Set ws2 = wb2.Sheets("PASTE")
ws2.Range("A1:A10").Value = ws1.Range("A1:A10").Value
ws2.Range("B1:B10").Value = ws1.Range("B1:B10").Value
End Sub
答案 0 :(得分:0)
我假设单元格C1在活动表中。
试试这个:
Set wb1 = Workbooks(ActiveSheet.Range("C1"))
希望得到这个帮助。
答案 1 :(得分:0)
感谢您的帮助,经过一番试验和错误,我得到了它的工作。这就是代码的样子:
Sub transfervalues()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set wb2 = ActiveWorkbook
Set ws2 = wb2.Sheets("Input Sheet")
Set wb1 = Workbooks(ActiveSheet.Range("C1").Value)
Set ws1 = wb1.Sheets("Output Sheet")
ws2.Range("A1:A10").Value = ws1.Range("A1:A10").Value
ws2.Range("B1:B10").Value = ws1.Range("B1:B10").Value
End Sub