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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tailored Macro - Excel 97

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I have not played around enough with Excel, but someone is asking me to solve their problems. They have a Macro which they simply recorded opening/importing a texfile into a worksheet. It works fine for them, however I am wanting to break up the vba code to offer, 1) Dir/Drive box for selecting a chosen textfile, after which the macro can import, and later ask if they want it saved. Is this task feaseable within Excel 97, if so any pointers of direction. Thanks
 
Try something like the following in order to select the file to import :
Code:
Filt = "Text files (*.txt),*.txt, " & _
       "Comma Seperated (*.csv),*.csv"
    FilterIndex = 1
    Title = "Select text File to Import and Process"
    Filename = Application.GetOpenFilename(FileFilter:=Filt, FilterIndex:=FilterIndex, Title:=Title)
    If Filename = False Then Exit Sub

    Workbooks.OpenText Filename:=Filename, etc.....
where etc... is dependant on the structure of the data you are importing, and can most likely be taken from the recorded code.

Hope it gets you started.

A.C
 
Many thanks acron, but without looking too much like an idiot where does this code get put. I am completely new to Excel, only worked with Visual Basic and feel at home with forms and command events triggered from contols getting clicked. Excel just stares at me. If you can enlighten me a bit more it would be very much appreciated, meanwhile I will sandwich the above into the macro and see if it wakes up. Thanks again
 
Made myself an idiot okay, I put the code inside the macro and it burst into life. Many thanks. All I need to know now to continue towards looking like a true expert is how do I arrange for the macro to fire up outomatically as soon as the workbook is opened. ??
 
You could rename it Sub Auto_Open, if you cannot place it the Workbook_Open event of the Thisworkbook object.

A.C.
 
Many thanks again acron, that did it, changed the macro name and it fires up. Your help very much appreciated, have a good weekend. Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top