Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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-插入引用已关闭工作簿的公式,运行时错误';1004';:_Vba_Excel - Fatal编程技术网

VBA-插入引用已关闭工作簿的公式,运行时错误';1004';:

VBA-插入引用已关闭工作簿的公式,运行时错误';1004';:,vba,excel,Vba,Excel,我正在尝试使用VBA将公式插入单元格,该公式是一个索引,并与关闭的工作簿相匹配。我收到一个运行时错误“1004”:应用程序定义的或对象定义的错误: Sub forecastData() Worksheets("Mon").Range("R17").Formula = "=INDEX(""'""L:\ECommerce\Trading\Web Analytics\Reporting\KPI\[Ecom KPI.xlsm]Forecast""'""!$B$6:$B$2927,MATCH(""'""

我正在尝试使用VBA将公式插入单元格,该公式是一个索引,并与关闭的工作簿相匹配。我收到一个运行时错误“1004”:应用程序定义的或对象定义的错误:

Sub forecastData()

Worksheets("Mon").Range("R17").Formula = "=INDEX(""'""L:\ECommerce\Trading\Web Analytics\Reporting\KPI\[Ecom KPI.xlsm]Forecast""'""!$B$6:$B$2927,MATCH(""'""Update Data""'""!$E$2,""'""L:\ECommerce\Trading\Web Analytics\Reporting\KPI\[Ecom KPI.xlsm]Forecast""'""!$A$6:$A$2927,0))"

End Sub
有人能看出我哪里出了错吗


干杯

无需担心,使用Chr(39)修复它:

Worksheets("Mon").Range("R17").Formula = "=INDEX(" + Chr(39) + "L:\ECommerce\Trading\Web Analytics\Reporting\KPI\[Ecom KPI.xlsm]Forecast" + Chr(39) + "!$B$6:$B$2927,MATCH(" + Chr(39) + "Update Data" + Chr(39) + "!$E$2," + Chr(39) + "L:\ECommerce\Trading\Web Analytics\Reporting\KPI\[Ecom KPI.xlsm]Forecast" + Chr(39) + "!$A$6:$A$2927,0))"