View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sue D[_2_] Sue D[_2_] is offline
external usenet poster
 
Posts: 1
Default Err 1004 when move Workbooks.OpenText to called Sub

I am trying to tidy up some VBA code by putting it in a Called Sub
When I use Workbooks.Opentext in the original code as for example

sFilename = sPath & "F59080"
sWbookname = sPath & "x80G01.xls"
Workbooks.OpenText FileName:=sFilename, _
Origin:=xlWindows, _
StartRow:=1, DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(2, 2), Array(27, 2), Array(137, 2), Array(150, 2))

It works.

But if I put it in a called Sub as

Sub texToWB(Wb As String, Textfile As String, Arr As String, GrpId As String)

If Dir(Textfile) < "" Then
Workbooks.OpenText FileName:=Textfile, _
Origin:=xlWindows, _
DataType:=xlFixedWidth, FieldInfo:=Array(Arr)
Else
MsgBox Textfile & " doesn't exist"
End If

It fails with Error 1004.

I am running Office 2003 and Windows XP