VBA中出现Range对象作用于Worksheet失败,求指正 10
代码如下:DimDataWBAsWorkbookSetDataWB=Opentxt20(DataFname)DimDataWSAsWorksheetSetDataWS=D...
代码如下:
Dim DataWB As Workbook
Set DataWB = Opentxt20(DataFname)
Dim DataWS As Worksheet
Set DataWS = DataWB.Worksheets(1)
Dim PdtNameDWB As Range
Set PdtNameDWB = DataWS.Range(Cells(1, 1), Cells(LastRowDWB, 1)) '?????
上面代码中自定义函数如下:
Function Opentxt20(ByRef Fname As String) As Workbook 'OFFICE2000
Workbooks.OpenText Filename:=Fname, Origin:=936, StartRow:=1, DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 9), Array(15, 1), Array(47, 9), Array(59, 1), Array(95, _
9), Array(105, 9), Array(125, 9), Array(133, 9)), TrailingMinusNumbers:=True
ActiveSheet.Columns("A:A").EntireColumn.AutoFit
ActiveSheet.Columns("B:B").EntireColumn.AutoFit
Set Opentxt20 = ActiveWorkbook
End Function
代码中标注?????的地方为系统报错处(错误号1004)。苦思一晚上,未解,现求教高人,谢谢! 展开
Dim DataWB As Workbook
Set DataWB = Opentxt20(DataFname)
Dim DataWS As Worksheet
Set DataWS = DataWB.Worksheets(1)
Dim PdtNameDWB As Range
Set PdtNameDWB = DataWS.Range(Cells(1, 1), Cells(LastRowDWB, 1)) '?????
上面代码中自定义函数如下:
Function Opentxt20(ByRef Fname As String) As Workbook 'OFFICE2000
Workbooks.OpenText Filename:=Fname, Origin:=936, StartRow:=1, DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 9), Array(15, 1), Array(47, 9), Array(59, 1), Array(95, _
9), Array(105, 9), Array(125, 9), Array(133, 9)), TrailingMinusNumbers:=True
ActiveSheet.Columns("A:A").EntireColumn.AutoFit
ActiveSheet.Columns("B:B").EntireColumn.AutoFit
Set Opentxt20 = ActiveWorkbook
End Function
代码中标注?????的地方为系统报错处(错误号1004)。苦思一晚上,未解,现求教高人,谢谢! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询