Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 从另一个文件导入数据时使用_Vba_Excel - Fatal编程技术网

Vba 从另一个文件导入数据时使用

Vba 从另一个文件导入数据时使用,vba,excel,Vba,Excel,我有一个源文件,用户可以在每个月的工作表中输入每月数据(多个工作表中有一月、二月、…)。 在另一个文件中,我希望用户输入年份和月份,我的宏应该从源文件导入相关数据。我尝试使用以下代码执行此任务,但收到无法识别的错误 strAsset_Path = Asset_RS_URL & "\" & strYear & "\" & Asset_RS_FILENAME & strMonth Set strAsset_CodeList = strAsset_Path &

我有一个源文件,用户可以在每个月的工作表中输入每月数据(多个工作表中有一月、二月、…)。 在另一个文件中,我希望用户输入年份和月份,我的宏应该从源文件导入相关数据。我尝试使用以下代码执行此任务,但收到无法识别的错误

strAsset_Path = Asset_RS_URL & "\" & strYear & "\" & Asset_RS_FILENAME & strMonth

Set strAsset_CodeList = strAsset_Path & strMonth.Range("A3:A500").Value

For Each MyCell In strAsset_CodeList
    Response.Write MyCell Range("A3:A500").Value
Next

通过vba打开另一个工作簿,读取并复制所选工作表中的单元格值:

strAsset_Path = Asset_RS_URL & "\" & strYear & "\" & Asset_RS_FILENAME 

Set wb = Workbooks.Open(strAsset_Path , ReadOnly:=True)

Set Rng = wb.Worksheets(strMonth).Range("A3:A500")

For Each mycell In Rng
    ThisWorkbook.Sheets("Sheet1").Range(mycell.Address).Value = wb.Worksheets(strMonth).Range(mycell.Address)
Next mycell

wb.Close