使Excel / VBA根据单元格值生成文件名

时间:2016-05-13 15:48:11

标签: excel excel-vba vba

我使用此代码将值从一个excel文件复制并粘贴到另一个excel文件中并且效果很好:

Sub TransferValues()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet



Set wb1 = Workbooks("ABC.xls") 
Set ws1 = wb1.Sheets("SHEET1") 

Set wb2 = Workbooks("CBA") 
Set ws2 = wb2.Sheets("SHEET2") 


'This line puts the value from wb1.ws1 in wb2.ws2, cells specified:
ws2.Range("O3:O33").Value = ws1.Range("I82:I112").Value
ws2.Range("O35:O65").Value = ws1.Range("J82:J112").Value


End Sub

但是,截至目前,我必须手动告诉VBA它必须抓住" ABC"文件。 有没有办法让Excel读取包含工作簿名称的单元格。 例如,工作簿CBAA1 ABC中说明了 我想的是:Set wb1 = Workbooks("(A1).xls") 谢谢!

0 个答案:

没有答案