VBA运行时错误1004 [英] VBA Run-Time Error 1004

查看:217
本文介绍了VBA运行时错误1004的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试以下错误消息结束的VBA宏:


运行时错误'1004'找不到p>

。检查文件名的拼写,并验证
文件位置是否正确。


如果您要打开从您最近使用的文件列表中的文件,请确保该文件未被重命名,移动或删除。



我检查了我没有使用删除/删除/重命名的文件,它们不是来自我的最近文件列表。



触发错误消息的代码的违规部分:

  Workbooks.OpenText文件名:= vCPath _ 
,Origin:= 437,StartRow:= 1,DataType:= xlDelimited,TextQualifier:= _
xlDoubleQuote,ConsecutiveDelimiter:= False,Tab:= False,分号:= False _
,逗号:= True,空格:= False,其他:= False,FieldInfo:= Array ),_
数组(2,1),数组(3,1),数组(4,1),数组(5,1),数组(6,1),数组(7,1),数组(8,1),_
数组(9,1),数组(10,1),数组(11,1),数组(12,1),数组(13,1)),_
TrailingMinusNumbers:= True

以下是所有代码:

 '更改程序以使
'平均排除异常值
'开发假数据一目了然识别程序是否工作。
'来源http://www.cpearson.com/excel/optimize.htm
'Declare .Filters
Option Explicit
Sub DataProcessingExperiment7()

On Error GoTo ErrorHandler
'声明为字符串,整数,作为变体,decDecimals,作为Office.FileDialog
Dim strPath,strFileN,strDirN,strRangeNOut,strRangeNIn,strFilename,strTLCorn,strBRCorn,strSelectedFile,strtemp_name As String
Dim vResMatrix(),vCPath,vFileN As Variant
Dim vRangeNOut,vRangeNIn,decInd6,decInd4,decInd5,decStep2,decMRow,decColIn,decInd3,decMcol As Double
Dim decMxRNo,decBgrSum ,decRowIn,decInd,decM40eff,decStep,decColNo,decStartcol,decStartrow As Double
Dim decPlateNo,decMonoVal,decInd1,decEntryRow2,decEntryRow,decInd2,decBgrValP,decBgrRow As Double
Dim decBrgSum,decBgrVal,decRangeNIn,decRangeNOut ,decTLCorn,decVolcorr,decBRCorn,decMEeff As Double
Dim decMediaVal,M40Eff,decMeanComp As Double
'MEeff = measure of efflux du e在闪烁中粗制纯化的HDL
'数学运算速度最快的是Integers / UIntegers:https://msdn.microsoft.com/en-us/library/ae55hdtk.aspx

'开始文件资源管理器选择包含数据的文件
Dim lngCount As Long
'打开文件对话框
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Show

'显示每个文件的路径
对于lngCount = 1 To .SelectedItems.Count
下一个lngCount
每个strFilename在.SelectedItems
MsgBox strFilename
下一个
结束

'Excel 2003是一个很好的过滤器选择:Excel Viewer,OpenOffice,+ Excel版本可以打开这些文件
'如果.Show = - 1用户选择至少一个文件
'用户按取消。
'从(1,2)到(7,2)中的参数位置分配字符串。这匹配模板
'现在使用相对引用来增加可移植性,而不是选择单元格以增加宏速度,缩短代码
使用ActiveCell
.Offset(1,2)= decPlateNo
.Offset(2,2)= decStartrow
.Offset(3,2)= decStartcol
.Offset(4,2)= decColNo
.Offset(5,2)= decStep
.Offset(6,2)= strDirN
.Offset(7,2)= strFileN
结束

' b $ b M40Eff = 4.37
M40Eff = 2.4

'选择并复制数据和范围
范围(A1:O22)。选择
Selection.Copy
MsgBoxstart
'使用数组
对于decInd = 1 to decPlateNo / 2 - 1
decRowIn = 1 + decStep * 2 * decInd
decRangeNIn =A + CStr(decRowIn)
范围(decRangeNIn)。选择
ActiveSheet.Paste
下一个decInd'转到下一个indice
Application.CutCopyMode = False'拥有两个表格中的数据

Workbooks.OpenText文件名:= vCPath _
,Origin:= 437,StartRow:= 1,DataType:= xlDelimited,TextQualifier:= _
xlDoubleQuote,ConsecutiveDelimiter:= False,Tab:= False,分号:= False _
,Comma:= True,Space:= False,其他:= False,FieldInfo:= Array(Array(1,1),_
数组(2,1),数组(3,1) ,Array(4,1),Array(5,1),Array(6,1),Array(7,1),Array(8,1),_
Array(9,1),Array 10,1),Array(11,1),Array(12,1),Array(13,1)),_
TrailingMinusNumbers:= True

对于decInd1 = 1 to decPlateNo '在这两列之间
decTLCorn =B+ CStr(decStartrow +(decInd1 - 1)* decStep)
decBRCorn =M+ CStr(decStartrow + 7 +(decInd1 - 1)* decStep )
decRangeNOut = decTLCorn +:+ decBRCorn
decRangeNIn = decTLCorn
Windows(vFileN).Activate
范围(vRangeNOut)。选择
Selection.Copy
Windows(strtemp_name).Activate
表格(Data)。选择
范围(vRangeNIn)。选择
Selection.PasteSpecial粘贴:= xlPast eValues,操作:= xlNone,SkipBlanks _
:= False,Transpose:= False
下一个decInd1
'操作:= xlNone在粘贴时减少计算(减少CPU密集度)
'不要跳过空格,不要转置

'计算单个板的背景和流出
对于decInd1 = 1 DecPlateNo / 2
decStep2 =(decInd1 - 1) * decStep * 2
decBgrRow = decStartrow + 8 + decStep2
decBgrValP = Cells(decBgrRow,2).Value'背板值
对于decInd2 = 0到7'从列Ind2到列7做乘法
decEntryRow = decStartrow + decInd2 + decStep2
decEntryRow2 = decStartrow + decInd2 + decStep2 + 11
decMediaVal = Cells(decEntryRow,13).Value
decMonoVal = Cells(decEntryRow2, 13).Value
Cells(decEntryRow,15).Value = decMEeff * 100 * decVolcorr *(decMediaVal - decBgrValP)/(decM40eff * decMonoVal + decVolcorr * decMEeff *(decMediaVal - decBgrValP))
下一个decInd2
下一个decInd1
MsgBoxend
'所有媒体平板的平均背景的计算
decBgrSum = 0
对于decInd1 = 1 DecPlateNo / 2
decStep2 =(decInd1 - 1)* decStep * 2
对于decInd2 = 0到7
decRowIn = decStartrow + decStep2 + decInd2
decBgrSum = decBgrSum + Cells (decRowIn,2).Value
下一个decInd2
下一个decInd1
decBgrVal = decBgrSum /(4 * decPlateNo)板分为4个(控制(媒体)板是其中2个)。
decBgrVal = Cells(2,17).Value
'重新排列数据并转移到结果表
decMxRNo = 8 * decColNo
ReDim vResMatrix(1 To decMxRNo,1 To decPlateNo)
Sheets(Data)。选择
对于decInd1 = 1 To decPlateNo
decMcol = decInd1
对于decInd2 = 1至8
decRowIn =(decInd1 - 1) * decStep + decStartrow + decInd2 - 1
对于decInd3 = 1到decColNo
decColIn = decStartcol + decInd3 - 1
decMRow =(decInd3 - 1)* 8 + decInd2
vResMatrix( decMRow,decMcol)=单元格(decRowIn,decColIn).Value
下一个decInd3
下一个decInd2
下一个decInd1

表格(Results)。选择
对于decInd4 = 1 DecPlateNo
对于decInd5 = 1到DecMxRNo
单元格(decInd5,decInd4).Value = vResMatrix(decInd5,decInd4)'将矩阵的值置于此范围内?
下一个decInd5
下一个decInd4
表格(结果QC)。选择
'选择QC(质量控制)计算
范围(C81:C82)。选择
Selection.Copy
对于decInd = 1 DecPlateNo / 2 - 1
decColIn = 2 + 2 * decInd + 1
单元格(81,decColIn)。选择
ActiveSheet.Paste'粘贴活动工作表的值(C81:C82范围)
下一个decInd

对于decInd4 = 1到decPlateNo
decInd6 = decInd4 + 2
对于decInd5 = 1到decMxRNo'将这些单元格值放在矩阵中
单元格(decInd5,decInd6).Value = vResMatrix(decInd5,decInd4)
下一个decInd5
下一个decInd4

对于decInd4 = 1 DecPlateNo
decInd6 = decInd4 + 2
decMeanComp = 0.6 *单元格(81,decInd6).Value
对于decInd5 = 1对于DecMxRNo
如果单元格(decInd5,decInd6).Value< decMeanComp然后
单元格(decInd5,decInd6).Interior.Color = RGB(255,0,0)
'如果单元格值小于平均值,则它们作为异常值突出显示为红色。 (更可能:从没有释放的移液器)
ElseIf Cells(decInd5,decInd6).Value> decMeanComp然后
单元格(decInd5,decInd6).Interior.Color = RGB(7,253,56)
'如果单元格值大于平均值,则高亮显示它们为异常值。 (不太可能除外)

结束If
下一个decInd5
下一个decInd4
MsgBox4
ErrorHandler:
MsgBoxError Code& ;错误编号& vbNewLine& Err.Description,vbCritical,Error Code& Err.Number
End Sub
'继续安排数据的另一个功能。首先声明所有数据类型。
Sub Arrange_data()

错误GoTo ErrorHandler

Dim strPath,strFileN,strDirN,strCPath,strRangeNOut,strRangeNIn,strTLCorn,strBRCorn As String
Dim decColIn4:decColIn4 = CDec(decColIn4)
Dim decInd5:decInd5 = CDec(decInd5)
Dim decInd6:decInd6 = CDec(decInd6)
Dim decPlateNo:decPlateNo = CDec(decPlateNo)
Dim decStartrow:decStartrow = CDec(decStartrow)
Dim decStartcol:decStartcol = CDec(decStartcol)


表格(参数)选择
decPlateNo =单元格(1,2).Value
decStartrow = Cells(2,2).Values
decStartcol = Cells(3,2).Value
decColNo = Cells(4,2).Value
decStep = Cells(5,2).Value
decMEeff = 2.03
decM40eff = 4.37'microscint 40 =巨噬细胞在
中解决的解决方案decVolcorr = 2.4
decMxRNo = 8 * decColNo
ReDim vResMatrix(1 To decMxRNo,1 To decPlateNo)

'选择QC(质量控制)数据
表格(结果QC)。选择
对于decInd1 = 1 To de cPlateNo
decInd3 = decInd1 + 2
对于decInd2 = 1到iMxRNo
vResMatrix(decInd2,decInd1)= Cells(decInd2,decInd3).Value
下一个decInd2
下一个decInd1
'传输两种外排计算方法的数据。
'创建列的模板。
Sheets(Processed indiv)。选择
范围(C2:E87)。选择
Selection.Copy
对于decInd = 1 to decPlateNo / 2 - 1
decColIn = 3 + 3 * decInd
单元格(2,decColIn)。选择
ActiveSheet.Paste
下一个decInd
Application.CutCopyMode = False
'Don' t剪切和复制:将值留在Excel工作表中。
'用于排除存储在矩阵中的值并计算流出。
对于decInd1 = 1 to decPlateNo / 2
decColIn1 = 3 + 3 *(decInd1 - 1)
decColIn2 = decColIn1 + 1
decColIn3 = decColIn1 + 2
decBgrRow =(decInd1 - 1)* decStep * 2 + decStartrow + 8
decInd4 = 2 * decInd1
decInd3 = decInd4 - 1
单元格(1,decStartcol + 3 *(decInd1 - 1)) .Value =Plate+ CStr(decInd1)
'获取板的背景值。
Sheets(Data)。选择
decBgrValP = Cells(decBgrRow,2)
表格(Processed indiv)。选择
'挖掘值并计算流出。
对于decInd2 = 1到iMxRNo
decMediaVal = vResMatrix(decInd2,decInd3)
decMonoVal = vResMatrix(decInd2,decInd4)
单元格(2 + decInd2,decColIn1).Value = decMediaVal
单元格(2 + decInd2,decColIn2).Value = decMonoVal
单元格(2 + decInd2,decColIn3).Value = decMEeff * 100 * decVolcorr *(decMediaVal - decBgrValP)/(decM40eff * decMonoVal + decVolcorr * decMEeff *(decMediaVal - decBgrValP))
下一个decInd2
下一个decInd1
'不删除任何数据单元格。
对于decInd1 = 1 DecPlateNo / 2
decColIn1 = 3 + 3 *(decInd1 - 1)
对于decInd2 = 3对于DecMxRNo + 2
如果Cells(decInd2,decColIn1) .Value =然后
单元格(decInd2,decColIn1 + 1).Value =
单元格(decInd2,decColIn1 + 2).Value =
End If
Next decInd2
下一个decInd1
'根据平均值计算数据。
'为列创建模板。选择
范围(C2:E87)。选择
Selection.Copy
对于decInd = 1 to decPlateNo / 2 - 1
decColIn = 3 + 3 * decInd
单元格(2,decColIn)。选择
ActiveSheet.Paste
下一个decInd
Application.CutCopyMode = False
'Prep用于排除存储在矩阵中的值并计算流出。
对于decInd1 = 1 to decPlateNo / 2
decColIn1 = 3 + 3 *(decInd1 - 1)
decColIn2 = decColIn1 + 1
decColIn3 = decColIn1 + 2
decBgrRow =(decInd1 - 1)* decStep * 2 + decStartrow + 8
decInd4 = 2 * decInd1
decInd3 = decInd4 - 1
单元格(1,decStartcol + 3 *(decInd1 - 1)) .Value =Plate+ CStr(decInd1)
'获取板的背景值。
Sheets(Data)。选择
decBgrValP = Cells(decBgrRow,2)
表格(按板进行处理)选择
'挖掘值并计算流出。
'这个循环是什么时候结束的?
对于decInd2 = 1到DecMxRNo
单元格(2 + decInd2,decColIn1).Value = vResMatrix(decInd2,decInd3)
单元格(2 + decInd2,decColIn2).Value = vResMatrix(decInd2, decInd4)
下一个decInd2
'获取单层的平均值。 (细胞处于1细胞深层)。
decMonoVal =单元格(83,decColIn2).Value
对于decInd2 = 1到DecMxRNo
decMediaVal = vResMatrix(decInd2,decInd3)
单元格(2 + decInd2,decColIn3).Value = decMEeff * 100 * decVolcorr *(decMediaVal - decBgrValP)/(decM40eff * decMonoVal + decVolcorr * decMEeff *(decMediaVal - decBgrValP))
下一个decInd2
下一个decInd1
'删除没有数据单元格。
对于decInd1 = 1 DecPlateNo / 2
decColIn1 = 3 + 3 *(decInd1 - 1)
对于decInd2 = 3对于DecMxRNo + 2
如果Cells(decInd2,decColIn1) .Value =然后
单元格(decInd2,decColIn1 + 1).Value =
单元格(decInd2,decColIn1 + 2).Value =
End If
下一个decInd2
下一个decInd1
'用矩阵中计算的流出替换细胞计数数据。
Sheets(Processed indiv)。选择
对于decInd1 = 1 DecPlateNo / 2
decColIn1 = 5 + 3 *(decInd1 - 1)
decInd4 = 2 * decInd1
对于decInd2 = 1到decMxRNo
vResMatrix(decInd2,decInd4)=单元格(2 + decInd2,decColIn1).Value
下一个decInd2
下一个decInd1
'将数据移动到重复比较。
表格(重复比较)选择
范围(C2:N87)。选择
Selection.Copy
对于decInd = 1到DecPlateNo / 4 - 1
decColIn = 3 + 12 * decInd
单元格(2,decColIn)。选择
ActiveSheet.Paste
下一个decInd
Application.CutCopyMode = False
对于decInd1 = 1 DecPlateNo / 4
decColIn1 = 3 + 12 *(decInd1 - 1)
decColIn2 = decColIn1 + 2
decColIn3 = decColIn1 + 3
decColIn4 = decColIn1 + 5
decInd3 = decInd1 * 4 - 3
decInd4 = decInd3 + 1
decInd5 = decInd3 + 2
decInd6 = decInd3 + 3
单元格(1,decStartcol + 12 *(decInd1 - 值=Plate+ CStr(2 * decInd1 - 1)
单元格(1,decStartcol + 3 + 12 *(decInd1 - 1))Value =Plate+ CStr(2 * decInd1 )
对于iInd2 = 1到iMxRNo
单元格(2 + iInd2,iColIn1).Value = vResMatrix(decInd2,decInd3)
单元格(2 + iInd2,iColIn2).Value = vResMatrix(decInd2 ,decInd4)
单元格(2 + iInd2 ,iColIn3).Value = vResMatrix(decInd2,decInd5)
单元格(2 + iInd2,iColIn4).Value = vResMatrix(decInd2,decInd6)
下一个decInd2
下一个decInd1
'不删除数据单元格。
对于decInd1 = 1到decPlateNo / 4
decColIn1 = 3 + 12 *(decInd1 - 1)
decColIn2 = decColIn1 + 3
对于decInd2 = 3 To decMxRNo + 2
如果单元格(decInd2,decColIn1).Value =然后
单元格(decInd2,decColIn1 + 1).Value =
对于decInd = 1至6
单元格(decInd2, decColIn1 + 5 + decInd).Value =
Next decInd
End If
如果Cells(decInd2,decColIn2).Value =Then
Cells(decInd2,decColIn2 + 1).Value =
对于decInd = 1至6
单元格(decInd2,decColIn2 + 2 + decInd).Value =
下一页iInd
结束If
下一个decInd2
下一个decInd1
'准备汇总统计信息。
decTL = decPlateNo * decMxRNo / 2
ReDim vResMatrix(1到4,1到iTL)
表格(Processed indiv)选择
decRowIn = 3 + decMxRNo
decRowIn2 = decRowIn + 1
对于decInd1 = 1至3 * decPlateNo / 2
对于decInd2 = 1至3
decRowIn3 = 3 *(decInd1 - 1)+ iInd2
decColIn = 2 + decRowIn3
vResMatrix(1,decRowIn3)= Cells(decRowIn,decColIn).Value
vResMatrix(2,decRowIn3)= Cells(decRowIn2,decColIn).Value
下一个decInd2
下一个decInd1
表格(由板处理)选择
decRowIn = 3 + iMxRNo
decRowIn2 = decRowIn + 1
对于decInd1 = 1 To 3 * decPlateNo / 2
对于decInd2 = 1到3
decRowIn3 = 3 *(decInd1 - 1)+ decInd2
decColIn = 2 + decRowIn3
vResMatrix(3,iRowIn3)= Cells(decRowIn, decColIn).Value
vResMatrix(4,decRowIn3)= Cells(decRowIn2,decColIn).Value
下一个decInd2
下一个decInd1
'将摘要统计信息在分销公司
Sheets(Distribution comp)。选择
对于decInd = 1至3 * decPlateNo / 2
单元格(2 + iInd,2).Value = vResMatrix(1,iInd)
单元格(2 + iInd,3).Value = vResMatrix(2,iInd)
单元格(2 + iInd,5).Value = vResMatrix(3,iInd)
单元格(2 + iInd, 6).Value = vResMatrix(4,iInd)
下一个decInd
'按板结果准备板。
表格(重复比较)选择
对于decInd = 1到iPlateNo / 4
decMatrixStep =(iInd - 1)* iMxRNo
decColIn = 9 + 12 *(iInd - 1)
decColIn2 = iColIn + 2
decColIn3 = iColIn + 1
decColIn4 = iColIn + 3
对于decInd2 = 1 To decMxRNo
decMRow = iMatrixStep + decInd2
'转换为范围的重复项之间的差异
vResMatrix(1,iMRow)=单元格(2 + decInd2,decColIn).Value
vResMatrix(2,iMRow)=单元格(2 + decInd2,decColIn2).Value / 2
vResMatrix 3,iMRow)=单元格(2 + decInd2,decColIn3).Value
vResMatrix(4,iMRow)=单元格(2 + decInd2,decColIn4).Value / 2
下一个decInd2
下一个decInd
'将数据传输到摘要。
表格(摘要)。选择
'准备工作表。
范围(B3:G82)。选择
Selection.Copy
对于decInd = 1 to decPlateNo / 4 - 1
decRowIn = 3 + decMxRNo * iInd
decRangeNIn =B+ CStr(decRowIn)
范围(decRangeNIn)。选择
ActiveSheet.Paste
对于decInd2 = 1到DecMxRNo
单元格(decInd2 + decRowIn - 1,1 ).Value =Plate+ CStr(decInd + 1)
下一个decInd2
下一个decInd
Application.CutCopyMode = False
'不要剪切并复制
分配价值。
对于decInd = 1到decTL
iRowIn = iInd + 2
单元格(decRowIn,4).Value = vResMatrix(1,decInd)
单元格(decRowIn,5).Value = vResMatrix(2,decInd)
单元格(decRowIn,6).Value = vResMatrix(3,decInd)
单元格(decRowIn,7).Value = vResMatrix(4,decInd)
下一步decInd
'将数据传输到Matrix摘要。
表格(矩阵摘要)。选择
'准备数据页面。
范围(A1:M11)。选择
Selection.Copy
对于decInd = 1 DecPlateNo / 4 - 1
decRowIn = 1 + decStep * decInd
decRangeNIn =A+ CStr(decRowIn)
范围(decRangeNIn)。选择
ActiveSheet.Paste
下一个decInd
Application.CutCopyMode = False
'分发数据。
对于decInd1 = 0到iPlateNo / 4 - 1
decPlateStep = decStep * decInd1
decMatrixStep = iColNo * 8 * decInd1
对于decInd2 = 0 To iColNo - 1
decColIn = decStartcol + decInd2
decColStep = 8 * iInd2
对于iInd3 = 0到7
iRowIn = iStartrow + iPlateStep + iInd3
iMxElem = iMatrixStep + iColStep + iInd3 + 1
Cells(decRowIn,decColIn).Value = vResMatrix(3,iMxElem)
下一个decInd3
下一个decInd2
下一个decInd1
'收集未知样本流出的统计参数。
decRowNo = decPlateNo / 4
ReDim decEffluxMatrix(1 To iRowNo,1 To 6)
decStartRowIn = 10
decStartColIn = 2
对于decInd = 0 To iRowNo - 1
decRowIn = iStartRowIn + iStep * iInd
EffluxMatrix(iInd + 1,1)= Cells(iRowIn,iStartColIn).Value
EffluxMatrix(iInd + 1,2)= Cells(iRowIn + 1 ,iStartColIn).Value
下一个decInd
'收集控制样本流出的统计参数。
Sheets(Data)。选择
decStartRowIn = 10
decStartColIn = 15
For iInd = 0 To iRowNo - 1
iRowIn = iStartRowIn + iStep * iInd * 4
EffluxMatrix(iInd + 1,3)= Cells(iRowIn,iStartColIn).Value
EffluxMatrix(iInd + 1,4)= Cells(iRowIn + 1,iStartColIn).Value
EffluxMatrix (iInd + 1,5)= Cells(iRowIn + 22,iStartColIn).Value
EffluxMatrix(iInd + 1,6)= Cells(iRowIn + 23,iStartColIn).Value
下一个decInd
'对流出的统计参数的输出
表(矩阵总结)选择
decStartRowOut = 4
decStartColOut = 15
对于decInd1 = 1 to decRowNo
decRowOut = decStartRowOut + decInd1 - 1
对于decInd2 = 1至6
decColOut = decStartColOut + decInd2 - 1
单元格(decRowOut,decColOut).Value = EffluxMatrix(decInd1,decInd2)
Next iInd2
下一个decInd1
'输出到矩阵最小最大
表格(矩阵最小最大值)。选择
对于decInd1 = 0到decPlateNo / 4 - 1
decPlateStep = decStep * decInd1
decMatrixStep = decColNo * 8 * decInd1
对于decInd2 = 0 DecColNo - 1
decColIn = decStartcol + iInd2
decColStep = 8 * decInd2
对于decInd3 = 0到7
decRowIn = decStartrow + decPlateStep + decInd3
decMxElem = decMatrixStep + decColStep + decInd3 + 1
单元格(decRowIn,decColIn).Value = vResMatrix(3,decMxElem)
下一个decInd3
下一个decInd2
下一个decInd1

ErrorHandler:
MsgBox检测到错误& vbNewLine& 错误&错误编号& :& Err.Description,vbCritical,Error Handler:Error& Err.Number
MsgBox如果要强制程序运行,请转到下面的行,并插入一个标记来评论该行。 &安培; vbNewLine& On Error GoTo ErrorHandler,vbCritical,Error Handler:Error& Err.Number
End Sub


解决方案

在初始化之前尝试使用变量 vCPath


I am debugging a VBA macro which ends with the following error message:

"Run-time error '1004':

"could not be found. Check the spelling of the file name, and verify that the file location is correct.

If you are trying to open the file from your list of most recently used files, make sure that the file has not been remnamed, moved, or deleted."

I checked that I was not using deleted/removed/renamed files and they were not coming from my Recent Files list.

The offending portion of the code which triggers the error message:

Workbooks.OpenText Filename:=vCPath _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1)), _
TrailingMinusNumbers:=True

Here is all of the code:

' Changes to program to make
' Exclude outliers in average
' Develop fake data to at glance recognize whether program works.
' Source http://www.cpearson.com/excel/optimize.htm
' Declare .Filters
Option Explicit
Sub DataProcessingExperiment7()

On Error GoTo ErrorHandler
'   Declare as strings, as integers, as variants, decDecimals, as Office.FileDialog
Dim strPath, strFileN, strDirN, strRangeNOut, strRangeNIn, strFilename, strTLCorn, strBRCorn, strSelectedFile, strtemp_name As String
Dim vResMatrix(), vCPath, vFileN As Variant
Dim vRangeNOut, vRangeNIn, decInd6, decInd4, decInd5, decStep2, decMRow, decColIn, decInd3, decMcol As Double
Dim decMxRNo, decBgrSum, decRowIn, decInd, decM40eff, decStep, decColNo, decStartcol, decStartrow As Double
Dim decPlateNo, decMonoVal, decInd1, decEntryRow2, decEntryRow, decInd2, decBgrValP, decBgrRow As Double
Dim decBrgSum, decBgrVal, decRangeNIn, decRangeNOut, decTLCorn, decVolcorr, decBRCorn, decMEeff As Double
Dim decMediaVal, M40Eff, decMeanComp As Double
'   MEeff = measure of efflux due to crudely purified HDL in scintillation
'   Math operations are fastest with Integers / UIntegers: https://msdn.microsoft.com/en-us/library/ae55hdtk.aspx

'   Start File Explorer to select file containing data
Dim lngCount As Long
' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
    .AllowMultiSelect = True
    .Show

'   Display paths of each file selected
    For lngCount = 1 To .SelectedItems.Count
    Next lngCount
    For Each strFilename In .SelectedItems
        MsgBox strFilename
    Next
End With

'   Excel 2003 is a good filter choice: Excel Viewer, OpenOffice, + Excel versions can open these files
'   If .Show = - 1 user picked at least one file
    ' The user pressed cancel.
'   Assign strings to param locations from (1,2) to (7,2). This matches template
'   Now using relative references to increase portability and NOT SELECTING the cells to increase macro speed, shorten code
With ActiveCell
    .Offset(1, 2) = decPlateNo
    .Offset(2, 2) = decStartrow
    .Offset(3, 2) = decStartcol
    .Offset(4, 2) = decColNo
    .Offset(5, 2) = decStep
    .Offset(6, 2) = strDirN
    .Offset(7, 2) = strFileN
End With

'   Measure of efflux of 2 plates of scint-40
M40Eff = 4.37
M40Eff = 2.4

'   Select and copy data and range
Range("A1:O22").Select
Selection.Copy
MsgBox "start"
'   Use the array
For decInd = 1 To decPlateNo / 2 - 1
    decRowIn = 1 + decStep * 2 * decInd
    decRangeNIn = "A" + CStr(decRowIn)
    Range(decRangeNIn).Select
    ActiveSheet.Paste
Next decInd 'Go to next indice
Application.CutCopyMode = False ' Have the data in both sheets

Workbooks.OpenText Filename:=vCPath _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1)), _
TrailingMinusNumbers:=True

For decInd1 = 1 To decPlateNo 'Between these 2 columns
    decTLCorn = "B" + CStr(decStartrow + (decInd1 - 1) * decStep)
    decBRCorn = "M" + CStr(decStartrow + 7 + (decInd1 - 1) * decStep)
    decRangeNOut = decTLCorn + ":" + decBRCorn
    decRangeNIn = decTLCorn
    Windows(vFileN).Activate
    Range(vRangeNOut).Select
    Selection.Copy
    Windows(strtemp_name).Activate
    Sheets("Data").Select
    Range(vRangeNIn).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Next decInd1
'   Operation:=xlNone prevents calculations while pasting (less CPU intensive)
'   Don't skip blanks, don't transpose

'   Calculation of background and efflux for individual plates
For decInd1 = 1 To decPlateNo / 2
    decStep2 = (decInd1 - 1) * decStep * 2
    decBgrRow = decStartrow + 8 + decStep2
    decBgrValP = Cells(decBgrRow, 2).Value 'Background plate value
    For decInd2 = 0 To 7 'From column Ind2 to column 7 do multiplication
        decEntryRow = decStartrow + decInd2 + decStep2
        decEntryRow2 = decStartrow + decInd2 + decStep2 + 11
        decMediaVal = Cells(decEntryRow, 13).Value
        decMonoVal = Cells(decEntryRow2, 13).Value
        Cells(decEntryRow, 15).Value = decMEeff * 100 * decVolcorr * (decMediaVal - decBgrValP) / (decM40eff * decMonoVal + decVolcorr * decMEeff * (decMediaVal - decBgrValP))
    Next decInd2
Next decInd1
MsgBox "end"
'   calculation of average background for all media plates
decBgrSum = 0
For decInd1 = 1 To decPlateNo / 2
    decStep2 = (decInd1 - 1) * decStep * 2
    For decInd2 = 0 To 7
        decRowIn = decStartrow + decStep2 + decInd2
        decBgrSum = decBgrSum + Cells(decRowIn, 2).Value
    Next decInd2
Next decInd1
decBgrVal = decBgrSum / (4 * decPlateNo) 'The plates are split up into 4 (control (media) plates are 2 of them).
decBgrVal = Cells(2, 17).Value
'   Rearanging data and transferring to Results sheet
decMxRNo = 8 * decColNo
ReDim vResMatrix(1 To decMxRNo, 1 To decPlateNo)
Sheets("Data").Select
For decInd1 = 1 To decPlateNo
    decMcol = decInd1
    For decInd2 = 1 To 8
        decRowIn = (decInd1 - 1) * decStep + decStartrow + decInd2 - 1
        For decInd3 = 1 To decColNo
            decColIn = decStartcol + decInd3 - 1
            decMRow = (decInd3 - 1) * 8 + decInd2
            vResMatrix(decMRow, decMcol) = Cells(decRowIn, decColIn).Value
        Next decInd3
    Next decInd2
Next decInd1

Sheets("Results").Select
For decInd4 = 1 To decPlateNo
    For decInd5 = 1 To decMxRNo
        Cells(decInd5, decInd4).Value = vResMatrix(decInd5, decInd4) 'Put the values of the matrix in this range?
    Next decInd5
Next decInd4
Sheets("Results QC").Select
'   Select QC (quality control) calculation
Range("C81:C82").Select
Selection.Copy
For decInd = 1 To decPlateNo / 2 - 1
    decColIn = 2 + 2 * decInd + 1
    Cells(81, decColIn).Select
    ActiveSheet.Paste 'Paste values of the active sheet (C81:C82 range)
Next decInd

For decInd4 = 1 To decPlateNo
    decInd6 = decInd4 + 2
    For decInd5 = 1 To decMxRNo 'Put these cell values in the matrix
        Cells(decInd5, decInd6).Value = vResMatrix(decInd5, decInd4)
    Next decInd5
Next decInd4

For decInd4 = 1 To decPlateNo
decInd6 = decInd4 + 2
decMeanComp = 0.6 * Cells(81, decInd6).Value
For decInd5 = 1 To decMxRNo
    If Cells(decInd5, decInd6).Value < decMeanComp Then
    Cells(decInd5, decInd6).Interior.Color = RGB(255, 0, 0)
'           If the cell value is less than the average highlight them red as outliers. (More likely: from pipettes that didn't release)
    ElseIf Cells(decInd5, decInd6).Value > decMeanComp Then
    Cells(decInd5, decInd6).Interior.Color = RGB(7, 253, 56)
'           If the cell value is greater than the average highlight them green as outliers. (Unlikely unless )

    End If
Next decInd5
Next decInd4
MsgBox "4"
ErrorHandler:
MsgBox "Error Code" & Err.Number & vbNewLine & Err.Description, vbCritical, "Error Code" & Err.Number
End Sub
' Another function to continue arranging the data. Start by declaring all data types.
Sub Arrange_data()

On Error GoTo ErrorHandler

Dim strPath, strFileN, strDirN, strCPath, strRangeNOut, strRangeNIn, strTLCorn, strBRCorn As String
Dim decColIn4: decColIn4 = CDec(decColIn4)
Dim decInd5: decInd5 = CDec(decInd5)
Dim decInd6: decInd6 = CDec(decInd6)
Dim decPlateNo: decPlateNo = CDec(decPlateNo)
Dim decStartrow: decStartrow = CDec(decStartrow)
Dim decStartcol: decStartcol = CDec(decStartcol)


Sheets("Parameters").Select
decPlateNo = Cells(1, 2).Value
decStartrow = Cells(2, 2).Values
decStartcol = Cells(3, 2).Value
decColNo = Cells(4, 2).Value
decStep = Cells(5, 2).Value
decMEeff = 2.03
decM40eff = 4.37 'microscint 40=kind of solution the macrophages go in
decVolcorr = 2.4
decMxRNo = 8 * decColNo
ReDim vResMatrix(1 To decMxRNo, 1 To decPlateNo)

'   Select QC (quality control) data
Sheets("Results QC").Select
For decInd1 = 1 To decPlateNo
    decInd3 = decInd1 + 2
    For decInd2 = 1 To iMxRNo
        vResMatrix(decInd2, decInd1) = Cells(decInd2, decInd3).Value
    Next decInd2
Next decInd1
'   Transfer data for two methods of efflux calculations.
'   Create template of columns.
Sheets("Processed indiv").Select
Range("C2:E87").Select
Selection.Copy
For decInd = 1 To decPlateNo / 2 - 1
    decColIn = 3 + 3 * decInd
    Cells(2, decColIn).Select
    ActiveSheet.Paste
Next decInd
Application.CutCopyMode = False
'   Don't cut and copy: leave the values in the Excel sheet.
'    For disgorging values stored in matrix and calculate efflux.
For decInd1 = 1 To decPlateNo / 2
    decColIn1 = 3 + 3 * (decInd1 - 1)
    decColIn2 = decColIn1 + 1
    decColIn3 = decColIn1 + 2
    decBgrRow = (decInd1 - 1) * decStep * 2 + decStartrow + 8
    decInd4 = 2 * decInd1
    decInd3 = decInd4 - 1
    Cells(1, decStartcol + 3 * (decInd1 - 1)).Value = "Plate " + CStr(decInd1)
'       Get background value for the plate.
    Sheets("Data").Select
    decBgrValP = Cells(decBgrRow, 2)
    Sheets("Processed indiv").Select
'       Digorging values and calculating efflux.
    For decInd2 = 1 To iMxRNo
        decMediaVal = vResMatrix(decInd2, decInd3)
        decMonoVal = vResMatrix(decInd2, decInd4)
        Cells(2 + decInd2, decColIn1).Value = decMediaVal
        Cells(2 + decInd2, decColIn2).Value = decMonoVal
        Cells(2 + decInd2, decColIn3).Value = decMEeff * 100 * decVolcorr * (decMediaVal - decBgrValP) / (decM40eff * decMonoVal + decVolcorr * decMEeff * (decMediaVal - decBgrValP))
    Next decInd2
Next decInd1
'   Remove no data cells.
For decInd1 = 1 To decPlateNo / 2
    decColIn1 = 3 + 3 * (decInd1 - 1)
    For decInd2 = 3 To decMxRNo + 2
        If Cells(decInd2, decColIn1).Value = "" Then
            Cells(decInd2, decColIn1 + 1).Value = ""
            Cells(decInd2, decColIn1 + 2).Value = ""
        End If
    Next decInd2
Next decInd1
'   calculate data based on plate average.
'   Create template for columns.
Sheets("Processed by plate").Select
Range("C2:E87").Select
Selection.Copy
For decInd = 1 To decPlateNo / 2 - 1
    decColIn = 3 + 3 * decInd
    Cells(2, decColIn).Select
    ActiveSheet.Paste
Next decInd
Application.CutCopyMode = False
'   Prep for disgorging values stored in matrix and calculate efflux.
For decInd1 = 1 To decPlateNo / 2
    decColIn1 = 3 + 3 * (decInd1 - 1)
    decColIn2 = decColIn1 + 1
    decColIn3 = decColIn1 + 2
    decBgrRow = (decInd1 - 1) * decStep * 2 + decStartrow + 8
    decInd4 = 2 * decInd1
    decInd3 = decInd4 - 1
    Cells(1, decStartcol + 3 * (decInd1 - 1)).Value = "Plate " + CStr(decInd1)
'       Get background value for the plate.
    Sheets("Data").Select
    decBgrValP = Cells(decBgrRow, 2)
    Sheets("Processed by plate").Select
'       Digorging values and calculating efflux.
'       When does this for loop end?
    For decInd2 = 1 To decMxRNo
        Cells(2 + decInd2, decColIn1).Value = vResMatrix(decInd2, decInd3)
        Cells(2 + decInd2, decColIn2).Value = vResMatrix(decInd2, decInd4)
    Next decInd2
'       Get average value for monolayer. (Cells are in 1-cell deep layer.) ?
    decMonoVal = Cells(83, decColIn2).Value
    For decInd2 = 1 To decMxRNo
        decMediaVal = vResMatrix(decInd2, decInd3)
        Cells(2 + decInd2, decColIn3).Value = decMEeff * 100 * decVolcorr * (decMediaVal - decBgrValP) / (decM40eff * decMonoVal + decVolcorr * decMEeff * (decMediaVal - decBgrValP))
    Next decInd2
Next decInd1
'   Remove no data cells.
For decInd1 = 1 To decPlateNo / 2
    decColIn1 = 3 + 3 * (decInd1 - 1)
    For decInd2 = 3 To decMxRNo + 2
        If Cells(decInd2, decColIn1).Value = "" Then
            Cells(decInd2, decColIn1 + 1).Value = ""
            Cells(decInd2, decColIn1 + 2).Value = ""
        End If
    Next decInd2
Next decInd1
'   Replace cell count data with calculated efflux in the matrix.
Sheets("Processed indiv").Select
For decInd1 = 1 To decPlateNo / 2
    decColIn1 = 5 + 3 * (decInd1 - 1)
    decInd4 = 2 * decInd1
    For decInd2 = 1 To decMxRNo
        vResMatrix(decInd2, decInd4) = Cells(2 + decInd2, decColIn1).Value
    Next decInd2
Next decInd1
'Move data to duplicate comparison.
Sheets("Duplicate comparison").Select
Range("C2:N87").Select
Selection.Copy
For decInd = 1 To decPlateNo / 4 - 1
    decColIn = 3 + 12 * decInd
    Cells(2, decColIn).Select
    ActiveSheet.Paste
Next decInd
Application.CutCopyMode = False
For decInd1 = 1 To decPlateNo / 4
    decColIn1 = 3 + 12 * (decInd1 - 1)
    decColIn2 = decColIn1 + 2
    decColIn3 = decColIn1 + 3
    decColIn4 = decColIn1 + 5
    decInd3 = decInd1 * 4 - 3
    decInd4 = decInd3 + 1
    decInd5 = decInd3 + 2
    decInd6 = decInd3 + 3
    Cells(1, decStartcol + 12 * (decInd1 - 1)).Value = "Plate " + CStr(2 * decInd1 - 1)
    Cells(1, decStartcol + 3 + 12 * (decInd1 - 1)).Value = "Plate " + CStr(2 * decInd1)
    For iInd2 = 1 To iMxRNo
        Cells(2 + iInd2, iColIn1).Value = vResMatrix(decInd2, decInd3)
        Cells(2 + iInd2, iColIn2).Value = vResMatrix(decInd2, decInd4)
        Cells(2 + iInd2, iColIn3).Value = vResMatrix(decInd2, decInd5)
        Cells(2 + iInd2, iColIn4).Value = vResMatrix(decInd2, decInd6)
    Next decInd2
Next decInd1
'   Remove no data cells.
For decInd1 = 1 To decPlateNo / 4
    decColIn1 = 3 + 12 * (decInd1 - 1)
    decColIn2 = decColIn1 + 3
    For decInd2 = 3 To decMxRNo + 2
        If Cells(decInd2, decColIn1).Value = "" Then
        Cells(decInd2, decColIn1 + 1).Value = ""
        For decInd = 1 To 6
            Cells(decInd2, decColIn1 + 5 + decInd).Value = ""
        Next decInd
        End If
If Cells(decInd2, decColIn2).Value = "" Then
    Cells(decInd2, decColIn2 + 1).Value = ""
    For decInd = 1 To 6
        Cells(decInd2, decColIn2 + 2 + decInd).Value = ""
    Next iInd
End If
Next decInd2
Next decInd1
'   Prepare summary statistics.
decTL = decPlateNo * decMxRNo / 2
ReDim vResMatrix(1 To 4, 1 To iTL)
Sheets("Processed indiv").Select
decRowIn = 3 + decMxRNo
decRowIn2 = decRowIn + 1
For decInd1 = 1 To 3 * decPlateNo / 2
    For decInd2 = 1 To 3
        decRowIn3 = 3 * (decInd1 - 1) + iInd2
        decColIn = 2 + decRowIn3
        vResMatrix(1, decRowIn3) = Cells(decRowIn, decColIn).Value
        vResMatrix(2, decRowIn3) = Cells(decRowIn2, decColIn).Value
    Next decInd2
Next decInd1
Sheets("Processed by plate").Select
decRowIn = 3 + iMxRNo
decRowIn2 = decRowIn + 1
For decInd1 = 1 To 3 * decPlateNo / 2
    For decInd2 = 1 To 3
        decRowIn3 = 3 * (decInd1 - 1) + decInd2
        decColIn = 2 + decRowIn3
        vResMatrix(3, iRowIn3) = Cells(decRowIn, decColIn).Value
        vResMatrix(4, decRowIn3) = Cells(decRowIn2, decColIn).Value
    Next decInd2
Next decInd1
'   Put summary statistics in distribution comp.
Sheets("Distribution comp").Select
For decInd = 1 To 3 * decPlateNo / 2
    Cells(2 + iInd, 2).Value = vResMatrix(1, iInd)
    Cells(2 + iInd, 3).Value = vResMatrix(2, iInd)
    Cells(2 + iInd, 5).Value = vResMatrix(3, iInd)
    Cells(2 + iInd, 6).Value = vResMatrix(4, iInd)
Next decInd
'   Prepare plate by plate results.
Sheets("Duplicate comparison").Select
For decInd = 1 To iPlateNo / 4
    decMatrixStep = (iInd - 1) * iMxRNo
    decColIn = 9 + 12 * (iInd - 1)
    decColIn2 = iColIn + 2
    decColIn3 = iColIn + 1
    decColIn4 = iColIn + 3
    For decInd2 = 1 To decMxRNo
        decMRow = iMatrixStep + decInd2
'           Difference between duplicates converted into range.
        vResMatrix(1, iMRow) = Cells(2 + decInd2, decColIn).Value
        vResMatrix(2, iMRow) = Cells(2 + decInd2, decColIn2).Value / 2
        vResMatrix(3, iMRow) = Cells(2 + decInd2, decColIn3).Value
        vResMatrix(4, iMRow) = Cells(2 + decInd2, decColIn4).Value / 2
    Next decInd2
Next decInd
'   Transfer data to Summary.
Sheets("Summary").Select
'   Prepare sheet.
Range("B3:G82").Select
Selection.Copy
For decInd = 1 To decPlateNo / 4 - 1
    decRowIn = 3 + decMxRNo * iInd
    decRangeNIn = "B" + CStr(decRowIn)
    Range(decRangeNIn).Select
    ActiveSheet.Paste
    For decInd2 = 1 To decMxRNo
        Cells(decInd2 + decRowIn - 1, 1).Value = "Plate " + CStr(decInd + 1)
    Next decInd2
Next decInd
Application.CutCopyMode = False
'   Don't cut and copy
'   Distribute values.
For decInd = 1 To decTL
    iRowIn = iInd + 2
    Cells(decRowIn, 4).Value = vResMatrix(1, decInd)
    Cells(decRowIn, 5).Value = vResMatrix(2, decInd)
    Cells(decRowIn, 6).Value = vResMatrix(3, decInd)
    Cells(decRowIn, 7).Value = vResMatrix(4, decInd)
Next decInd
'   Transfer data to Matrix summary.
Sheets("Matrix summary").Select
'   Prepare page for data.
Range("A1:M11").Select
Selection.Copy
For decInd = 1 To decPlateNo / 4 - 1
    decRowIn = 1 + decStep * decInd
    decRangeNIn = "A" + CStr(decRowIn)
    Range(decRangeNIn).Select
    ActiveSheet.Paste
Next decInd
Application.CutCopyMode = False
'   Distribute data.
For decInd1 = 0 To iPlateNo / 4 - 1
    decPlateStep = decStep * decInd1
    decMatrixStep = iColNo * 8 * decInd1
    For decInd2 = 0 To iColNo - 1
        decColIn = decStartcol + decInd2
        decColStep = 8 * iInd2
        For iInd3 = 0 To 7
            iRowIn = iStartrow + iPlateStep + iInd3
            iMxElem = iMatrixStep + iColStep + iInd3 + 1
            Cells(decRowIn, decColIn).Value = vResMatrix(3, iMxElem)
        Next decInd3
    Next decInd2
Next decInd1
'   collect statistical parameters on efflux for unknown samples.
decRowNo = decPlateNo / 4
ReDim decEffluxMatrix(1 To iRowNo, 1 To 6)
decStartRowIn = 10
decStartColIn = 2
For decInd = 0 To iRowNo - 1
    decRowIn = iStartRowIn + iStep * iInd
    EffluxMatrix(iInd + 1, 1) = Cells(iRowIn, iStartColIn).Value
    EffluxMatrix(iInd + 1, 2) = Cells(iRowIn + 1, iStartColIn).Value
Next decInd
'collect statistical parameters on efflux for control samples.
Sheets("Data").Select
decStartRowIn = 10
decStartColIn = 15
For iInd = 0 To iRowNo - 1
    iRowIn = iStartRowIn + iStep * iInd * 4
    EffluxMatrix(iInd + 1, 3) = Cells(iRowIn, iStartColIn).Value
    EffluxMatrix(iInd + 1, 4) = Cells(iRowIn + 1, iStartColIn).Value
    EffluxMatrix(iInd + 1, 5) = Cells(iRowIn + 22, iStartColIn).Value
    EffluxMatrix(iInd + 1, 6) = Cells(iRowIn + 23, iStartColIn).Value
Next decInd
'   Ouput of statistical parameters on efflux
Sheets("Matrix summary").Select
decStartRowOut = 4
decStartColOut = 15
For decInd1 = 1 To decRowNo
    decRowOut = decStartRowOut + decInd1 - 1
    For decInd2 = 1 To 6
        decColOut = decStartColOut + decInd2 - 1
        Cells(decRowOut, decColOut).Value = EffluxMatrix(decInd1, decInd2)
    Next iInd2
Next decInd1
'Output into Matrix min-max
Sheets("Matrix min-max").Select
For decInd1 = 0 To decPlateNo / 4 - 1
    decPlateStep = decStep * decInd1
    decMatrixStep = decColNo * 8 * decInd1
    For decInd2 = 0 To decColNo - 1
        decColIn = decStartcol + iInd2
        decColStep = 8 * decInd2
        For decInd3 = 0 To 7
            decRowIn = decStartrow + decPlateStep + decInd3
            decMxElem = decMatrixStep + decColStep + decInd3 + 1
            Cells(decRowIn, decColIn).Value = vResMatrix(3, decMxElem)
        Next decInd3
    Next decInd2
Next decInd1

ErrorHandler:
MsgBox "Error detected" & vbNewLine & "Error" & Err.Number & ": " & Err.Description, vbCritical, "Error Handler: Error " & Err.Number
MsgBox "If you want to force the program to run, go to the line below and insert a ' mark to comment the line out." & vbNewLine & "On Error GoTo ErrorHandler", vbCritical, "Error Handler: Error " & Err.Number
End Sub

解决方案

You are attempting to use the variable vCPath before you have initialized it.

这篇关于VBA运行时错误1004的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆