By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,590 Members | 663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,590 IT Pros & Developers. It's quick & easy.

Moving through files in a folder

Tig201
100+
P: 103
I am trying to go through the files in a folder and rename them but I am getting the error "Run-Time Error 5: Invalid procedure call or argument" on this bit of code
Expand|Select|Wrap|Line Numbers
  1. Dim myFileSysObj As New FileSystemObject, myFile As File, myFolder As Folder
  2. ...............
  3. For Cnt = 1 To myFolder.Files.Count Step 1
  4. ->  Set myFile = myFileSysObj.GetFile(myFolder.Files.Item(Cnt))
  5. Next Cnt
  6. .........
  7.  
can anybody explain this.
Thanks
Apr 23 '07 #1
Share this Question
Share on Google+
2 Replies


P: 47
I am trying to go through the files in a folder and rename them but I am getting the error "Run-Time Error 5: Invalid procedure call or argument" on this bit of code
Expand|Select|Wrap|Line Numbers
  1. Dim myFileSysObj As New FileSystemObject, myFile As File, myFolder As Folder
  2. ...............
  3. For Cnt = 1 To myFolder.Files.Count Step 1
  4. ->  Set myFile = myFileSysObj.GetFile(myFolder.Files.Item(Cnt))
  5. Next Cnt
  6. .........
  7.  
can anybody explain this.
Thanks
Hi,
Actually U did n't inatialized the Folder Path as well as Files from Specific Folder
I am giving u a sample code hope You will understand it. & fulfill your requiremnet
Expand|Select|Wrap|Line Numbers
  1. Dim fsys As New FileSystemObject
  2.  Dim fld As Folder
  3.  Dim FLS As Files
  4.  Dim Fl As File
  5.  
  6.  Set fld = fsys.GetFolder("C:\CA_ADVIC\Output\")
  7.  Set FLS = fld.Files
  8.  For Each Fl In FLS
  9.   Combo1.AddItem Fl.Name
  10.  Next
  11.  If Combo1.ListCount > 0 Then Combo1.ListIndex = 0
  12.  
try it .good luck. Wait for your responce.
Apr 23 '07 #2

Tig201
100+
P: 103
Thanks that did the trick
Apr 23 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.