Unqualified Reference: running excel in the background from Access Opening Text Doc

Rowrow

New Member
Joined
Jan 5, 2014
Messages
6
I have a minor problem with opening a text document in excel through access. As I am in Access I am assuming the array references in the .opentext... array, are unqualified.

Please give me your thoughts. I can problem work around the problem, but I hate leaving a problem unsolved (it is bound to crop up again).

Many Thanks
Row

Sub ProcessEpro(strDir As String)
Dim xl As Object
Dim strFile As String
strFile = Mid(strDir, 66, Len(strDir) - 69)
Set xl = CreateObject("Excel.Application")
<<< The problem is in here >>>

xl.workbooks.Opentext FileName:=strDir, _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlNone, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, Comma _
:=False, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 2), Array(2, _
2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2)), TrailingMinusNumbers:=True

<<<end problem="" of="">>>


xl.workbooks(strFile).Close
Set xl = Nothing
End Sub</end>
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Had to work around it a bit:

Wrote the code in excel and then called the sub from Access.

xl.run "Macro"

If anyone has a better solution I am still interested.

Thanks
Row
 
Upvote 0
I don't think it's the Array function that's the issue, it's the xl constants. Try this:
Code:
Sub ProcessEpro(strDir As String)
Const xlMSDOS as long = 3
Const xlDelimited as long = 1
const xlNone as long = -4142

Dim xl As Object
Dim strFile As String
strFile = Mid(strDir, 66, Len(strDir) - 69)
Set xl = CreateObject("Excel.Application")

xl.workbooks.Opentext FileName:=strDir, _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlNone, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, Comma _
:=False, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 2), Array(2, _
2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2)), TrailingMinusNumbers:=True
xl.workbooks(strFile).Close
Set xl = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,842
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top