Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Err 1004 when move Workbooks.OpenText to called Sub


Hello Sue,

The problem is with passing the array. In your Sub you're passing it a
a String. The Array must be a Variant. I have highlighted the problem i
red.

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

Change it to read...
Sub texToWB(Wb As String, Textfile As String, Arr As Variant, GrpId A
String

--
Leith Ros

-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=47820

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Err 1004 when move Workbooks.OpenText to called Sub

Thanks for taking the trouble to answer. Once I understood that I needed to
pass the Field Info, defining it as an Array held in variant datatype it all
fell into place and now works fine


"Leith Ross" wrote:


Hello Sue,

The problem is with passing the array. In your Sub you're passing it as
a String. The Array must be a Variant. I have highlighted the problem in
red.

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

Change it to read...
Sub texToWB(Wb As String, Textfile As String, Arr As Variant, GrpId As
String)


--
Leith Ross


------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=478205


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Workbooks.OpenText StartRow:=2 Not Skipping Row 1 John Saunders Excel Programming 2 August 26th 05 11:51 AM
Workbooks.OpenText does not work on XP. HELP !!! [email protected] Excel Programming 6 May 31st 05 03:18 PM
How to open UTF-8 files with Workbooks.OpenText Mete Kural Excel Programming 0 May 7th 05 01:25 AM
Runtime error 1004 with method OpenText - but only on one computer Kew[_2_] Excel Programming 0 August 30th 04 11:52 PM
Workbooks.OpenText Alistair Eberst Excel Programming 2 October 21st 03 12:50 PM


All times are GMT +1. The time now is 07:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"