Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default adding a string of data to an array

Hi,

I am trying to cycle through a series of files in a folder and if the
filename does not meet my criteria, then I want to add the filename to
my array. This is my loop. How do I add the filename to my array?

Sub ParseTextFiles()

Dim MyFile As String
Dim FSO As FileSystemObject
Dim MyFolder As Object
Dim ObjFile As Object
Dim colFiles As Object
Dim MyParsedMessage() As String
Dim MyParsedDate As String



MyFile = "Z:\Drop Box\robin.tanner\FortexRejects"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder(MyFile)
Set colFiles = MyFolder.Files

For Each ObjFile In colFiles
MyParsedDate =
Application.WorksheetFunction.Substitute(Left(ObjF ile.Name, 10), ".",
"/")
If Not IsDate(MyParsedDate) Then
MyParsedMessage(i) = ObjFile.Name
End If
Next

MsgBox MyParsedMessage(1:i)


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default adding a string of data to an array

You need a dynamic array. This is untested but it sould be close. I
personally would have used a collection of file objects but to each his own...

Sub ParseTextFiles()

Dim MyFile As String
Dim FSO As FileSystemObject
Dim MyFolder As Object
Dim ObjFile As Object
Dim colFiles As Object
Dim MyParsedMessage() As String
Dim MyParsedDate As String
Dim lng as long

MyFile = "Z:\Drop Box\robin.tanner\FortexRejects"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder(MyFile)
Set colFiles = MyFolder.Files

For Each ObjFile In colFiles
MyParsedDate =
Application.WorksheetFunction.Substitute(Left(ObjF ile.Name, 10), ".",
"/")
If Not IsDate(MyParsedDate) Then
Redim Preserve MyParsedMessage(lng)
MyParsedMessage(lng) = ObjFile.Name
lng = lng + 1
End If
Next

for lng = lbound(MyParsedMessage) to ubound(MyParsedMessage)
MsgBox MyParsedMessage(1:i)
next lng
End Sub

--
HTH...

Jim Thomlinson


"R Tanner" wrote:

Hi,

I am trying to cycle through a series of files in a folder and if the
filename does not meet my criteria, then I want to add the filename to
my array. This is my loop. How do I add the filename to my array?

Sub ParseTextFiles()

Dim MyFile As String
Dim FSO As FileSystemObject
Dim MyFolder As Object
Dim ObjFile As Object
Dim colFiles As Object
Dim MyParsedMessage() As String
Dim MyParsedDate As String



MyFile = "Z:\Drop Box\robin.tanner\FortexRejects"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder(MyFile)
Set colFiles = MyFolder.Files

For Each ObjFile In colFiles
MyParsedDate =
Application.WorksheetFunction.Substitute(Left(ObjF ile.Name, 10), ".",
"/")
If Not IsDate(MyParsedDate) Then
MyParsedMessage(i) = ObjFile.Name
End If
Next

MsgBox MyParsedMessage(1:i)


End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default adding a string of data to an array

On Sep 29, 3:01*pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
You need a dynamic array. This is untested but it sould be close. I
personally would have used a collection of file objects but to each his own...

Sub ParseTextFiles()

Dim MyFile As String
Dim FSO As FileSystemObject
Dim MyFolder As Object
Dim ObjFile As Object
Dim colFiles As Object
Dim MyParsedMessage() As String
Dim MyParsedDate As String
Dim lng as long

MyFile = "Z:\Drop Box\robin.tanner\FortexRejects"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder(MyFile)
Set colFiles = MyFolder.Files

For Each ObjFile In colFiles
* * MyParsedDate =
Application.WorksheetFunction.Substitute(Left(ObjF ile.Name, 10), ".",
"/")
* * If Not IsDate(MyParsedDate) Then
* * * * Redim Preserve MyParsedMessage(lng)
* * * * MyParsedMessage(lng) = ObjFile.Name
* * * * lng = lng + 1
* * End If
Next

for lng = lbound(MyParsedMessage) to ubound(MyParsedMessage)
* MsgBox MyParsedMessage(1:i)
next lng
End Sub

--
HTH...

Jim Thomlinson



"R Tanner" wrote:
Hi,


I am trying to cycle through a series of files in a folder and if the
filename does not meet my criteria, then I want to add the filename to
my array. *This is my loop. *How do I add the filename to my array?


Sub ParseTextFiles()


Dim MyFile As String
Dim FSO As FileSystemObject
Dim MyFolder As Object
Dim ObjFile As Object
Dim colFiles As Object
Dim MyParsedMessage() As String
Dim MyParsedDate As String


MyFile = "Z:\Drop Box\robin.tanner\FortexRejects"


Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder(MyFile)
Set colFiles = MyFolder.Files


For Each ObjFile In colFiles
* * MyParsedDate =
Application.WorksheetFunction.Substitute(Left(ObjF ile.Name, 10), ".",
"/")
* * If Not IsDate(MyParsedDate) Then
* * * * MyParsedMessage(i) = ObjFile.Name
* * End If
Next


MsgBox MyParsedMessage(1:i)


End Sub- Hide quoted text -


- Show quoted text -


oh I am more than open to suggestions Jim. I am just using what I
know. Please, tell me why a collection of file objects would be
better in your opinion...

Thank you for the fix by the way.
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
Adding rows to the data array used in an Index function Lanhing Excel Discussion (Misc queries) 1 April 7th 09 07:45 PM
String Array Karen53 Excel Programming 3 March 27th 08 06:37 AM
Adding Text to a String Gene Haines Excel Discussion (Misc queries) 1 November 29th 06 05:34 AM
String array initialisation [email protected] Excel Programming 2 June 29th 06 09:20 PM
Passing a String in Array to Range as String [email protected] Excel Programming 2 September 1st 04 01:13 AM


All times are GMT +1. The time now is 01:35 PM.

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

About Us

"It's about Microsoft Excel"