LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.office.developer.vba
external usenet poster
 
Posts: 7
Default "Folder Select" Dialogue - Opening multiple files from selected folder

Dear All

I have written a macro that takes three open text files (tab
delimited), moves them as worksheets into the 'mother' workbook
(containing the macro) and runs a load of calculations on them. To
save time, rather than opening the files one by one (and having to
click next, finish etc..) I recorded a macro to do this. It goes
something along the lines of...

Workbooks.OpenText Filename:= _
"X:\yz\abc.txt", Origin:=xlMSDOS, StartRow:=1, _
DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, _
Tab:=True, Semicolon:=False, Comma:=False, _
Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True

This is repeated three times for abc1.txt, abc2.txt &abc3.txt

However, it only takes the files from the same folder as when the macro
was recorded (X:\yz). This folder will be different every time the
macro is run (the three files will always be named the same though).

In order to do this I have copied some code that Lars-Eric Gisslén
submitted another topic (microsoft.public.word.vba.general "File Open
Dialogue") which uses the Folder Dialogue as such...

(blah, blah, Declarations, etc...)'
------------------------
Sub Test()
MsgBox SelectFolder("Choose a folder")
End Sub
------------------------
Private Function SelectFolder(sTitle) As String
blah blah blah...

This brings up the dialogue and once you have chosen a directory, reads
the path back to you in a message box.

This works fine. However, when I try to put my "open files" macro in
the place of the MsgBox bit, it doesn't work, the reason probably
being that I replace
Workbooks.OpenText Filename:= _
"X:\yz\abc.txt", Origin:=xlMSDOS, StartRow:=1, _

With...
Workbooks.OpenText Filename:= _
SelectFolder + "\abc.txt", Origin:=xlMSDOS, StartRow:=1, _


I have even tried doing the SelectFolder + "\abc.txt" bit outside the
'Workbooks.OpenText' bit by creating a single string variable to
combine the two, thusly...

Dim workdammit As String
workdammit = SelectFolder + "\abc.txt"
Workbooks.OpenText Filename:= _
workdammit, Origin:=xlMSDOS, StartRow:=1, _

EVERY time, it kicks back with "Compile Error: Argument not optional"
Can somebody please help me!!

I have tried to keep this as brief as possible, if this doesn't make
sense or for full details of the code, please just ask.

Many thanks

Rob

PS. Big shout out to all you guys on here, as someone who only started
VBA programming three weeks ago, these groups have been immeasurably
useful - keep up the good work!

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I prevent Excel 2007 from leaving ".tmp" files in my folder Deb M Excel Discussion (Misc queries) 5 June 4th 09 07:16 PM
How to decide folder-depth or How to select more folders/subfolders (folder-tree) ? Subteam Excel Discussion (Misc queries) 2 May 7th 06 08:14 PM
creating an XLS file from " files" data in a Folder Edwin Mashiringwani Excel Discussion (Misc queries) 2 November 19th 05 04:45 PM
Backup to specific folder if workbook names begins with "NSR" or "MAC" GregR Excel Programming 3 May 6th 05 12:24 AM


All times are GMT +1. The time now is 11:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"