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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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).
 

Mike H

Active Member
Joined
Feb 15, 2006
Messages
321
I need any monetary amounts to imported just as standard currency...

I recoreded the macro to open it...?
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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?
 

Mike H

Active Member
Joined
Feb 15, 2006
Messages
321

ADVERTISEMENT

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?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,328
Office Version
  1. 365
Platform
  1. Windows
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.
 

Mike H

Active Member
Joined
Feb 15, 2006
Messages
321
Thats a great point actually... I never thought of that!!! I see how it could confuse it!!

Thanks alot for the tip :)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,895
Messages
5,766,978
Members
425,392
Latest member
Booknerd

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
Top