Opening A Text File Problem

Mike H

Active Member
Joined
Feb 15, 2006
Messages
321
hi guys,

I have a problem when opening a text file, when i open it in excel by using file > open it imports fine through the text converter.

When i get VBA to do the same thing all the monetary values are carrying green tags which enable you to convert to number.

How can i get it to open via VBA without these tags appearing??

Cheers

Mike
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
How are you opening it? If you use the OpenText method (rather than the simple Open method say) then you can specify the FieldInfo (ie how it should be imported).
 
Upvote 0
I need any monetary amounts to imported just as standard currency...

I recoreded the macro to open it...?
 
Upvote 0
Please can you post your existing code. Is the format of the file constant? ie column 1 is ID, column 2 date, column 3 Amount etc etc?
 
Upvote 0
Here you go..

Code:
Sub opentext()


Application.DisplayAlerts = False

    ChDir "P:\MI Team\BOB TEXT EXPORTS"
    Workbooks.opentext Filename:= _
        "P:\MI Team\BOB TEXT EXPORTS\Total Secured Keyed.txt", Origin:=xlWindows, _
        StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=True, Comma:=False, _
        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
    Range("A3:M35").Select
    Selection.Copy
    Windows("Book11").Activate
    Range("A2").Select
    ActiveSheet.Paste
    Range("A1").Select
    Windows("Total Secured Keyed.txt").Activate
    ActiveWindow.Close
    
Application.DisplayAlerts = True

End Sub

When this is recorded it comes out fine originally... No green tags on the advance amount.... But when you run the VBA again afterwards it comes across wit hthe green tages on any currency values?
 
Upvote 0
Mike

It probably won't help with your problem but I would seriously suggest you don't call the sub opentext.

Notice how in the code opentext is lower case?

That should be OpenText.
 
Upvote 0
Thats a great point actually... I never thought of that!!! I see how it could confuse it!!

Thanks alot for the tip :)
 
Upvote 0

Forum statistics

Threads
1,222,151
Messages
6,164,246
Members
451,882
Latest member
Bigtop

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