Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 355
Default Loop through range and open files

Hello
I have a list of *.txt files in A1:F1. I have already written code to
define the path where the file is located (myPath). I need to open each file
and perform some formatting and then copy to another file. How do I loop
through the files using the content of the range?
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Loop through range and open files

Sandy,

Sub TryNow()
Dim myCell As Range
Dim myPath As String
myPath = "C:\Excel\"
For Each myCell In Range("A1:F1")
Workbooks.OpenText Filename:=myPath & myCell.Value
'Perform formatting
'Copy to other file
'If you want to save the file as a workbook, uncomment this
'ActiveWorkbook.SaveAs myPath & "NewFileName.xls", xlDefault
ActiveWorkbook.Close False
Next myCell
End Sub

HTH,
Bernie
MS Excel MVP


"Sandy" wrote in message
...
Hello
I have a list of *.txt files in A1:F1. I have already written code to
define the path where the file is located (myPath). I need to open each file
and perform some formatting and then copy to another file. How do I loop
through the files using the content of the range?
Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Loop through range and open files

dim myCell as range
dim myRng as range

set myrng = worksheets("sheet999").range("a1:F1")

for each mycell in myrng.cells
'do your work
msgbox mycell.value
next mycell



Sandy wrote:

Hello
I have a list of *.txt files in A1:F1. I have already written code to
define the path where the file is located (myPath). I need to open each file
and perform some formatting and then copy to another file. How do I loop
through the files using the content of the range?
Thanks!


--

Dave Peterson
Reply
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
open files in loop with date order [email protected] Excel Discussion (Misc queries) 5 September 24th 07 01:10 AM
OPen different files in a loop CmK Excel Programming 5 March 2nd 07 01:01 PM
Loop through ".DAT" files, open run code, close next Les Stout[_2_] Excel Programming 3 April 20th 06 10:15 AM
Open only existing Excel Files in a given Range Matty C[_2_] Excel Programming 1 October 5th 04 01:32 PM
Open only existing Excel Files in a given Range Matty C Excel Programming 1 October 4th 04 07:51 PM


All times are GMT +1. The time now is 11:50 PM.

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"