Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.txt to Excel- Naming

Status
Not open for further replies.

MrsMope

Technical User
Oct 18, 2004
125
US
Hello to all,
I have read the previous posts about using the macro recorded to import a text file into excel. My question is, what if the file is not the same name every time? how do I code that?

Thanks,
RB
 
Which code have you so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
Sub ImportExcel_Staff()
'
' ImportExcel_Staff Macro
' Macro recorded 12/4/2006 by Rayna Brandt
'
' Keyboard Shortcut: Ctrl+Shift+S
'
    ChDir "V:\FGS\Data_ARCHIVE\DataOUT"
    Workbooks.OpenText Filename:= _
        "V:\FGS\Data_ARCHIVE\DataOUT\FGSClaimStaff_20061204_072051.txt", Origin:=437 _
        , StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 2), Array( _
        11, 2), Array(23, 2), Array(26, 3), Array(34, 3), Array(42, 1), Array(51, 1), Array(62, 2), _
        Array(92, 2), Array(94, 2), Array(142, 2), Array(147, 9)), TrailingMinusNumbers:= _
        True
End Sub
 
Have you tried to play with the Dir function ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
No I haven't I will take a look at it.
Thanks,
RB
 
I ended up using the .GetOpenFileName method in VBA. Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top