?
Solved

VB invalid procedure call or argument

Posted on 2014-09-10
9
Medium Priority
?
104 Views
Last Modified: 2015-05-19
The code below was created to perform a directory listing on a local folder then output it comma delimited to a file on the network. It all works fine unless the listing comes across an invalid file name. In this case error 800A0005 (Invalid procedure call or argument is thrown up on line 14 char 2. Is there some method to ignore such a file or change how the data is output to allow its inclusion. If the only method is to output to an un-delimited text file that would be ok too. I have limited experience so if possible to resolve please modify. All I really need is an out to a file with the directory contents, no bells or whistles if that's what it takes.

Regards
S

Set objFSO = CreateObject("Scripting.FileSystemObject")
 Dim WshNetwork
 Set WshNetwork = CreateObject("WScript.Network")
 ComputerName = WshNetwork.ComputerName

 set WshShell = WScript.CreateObject("WScript.Shell")
 strDesktop = WshShell.SpecialFolders ("Desktop")

 strRootFolder = strDesktop & "\FOLDER"
 strOutputFile = "\\serverdc02\office\SoftHardAudit\ConfDir\LaptopConfDirListings" & "\" & computername & "DirListing.csv"
 strResults = ""
 EnumerateFolder(strRootFolder)
 Set objOutput = objFSO.CreateTextFile(strOutputFile, True)
 objOutput.Write strResults
 objOutput.Close

 Sub EnumerateFolder(objFolder)
       For Each objFile In objFSO.GetFolder(objFolder).Files
             If strResults = "" Then
                   strResults = """" & Replace(objFile.Path, "\", """,""") & """"
             Else
                   strResults = strResults & VbCrLf & """" & Replace(objFile.Path, "\", """,""") & """"
             End If
       Next
       For Each objSubFolder In objFSO.GetFolder(objFolder).SubFolders
             EnumerateFolder objSubFolder
       Next
 End Sub

Open in new window

0
Comment
Question by:SimonJohnG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 51

Accepted Solution

by:
Vitor Montalvão earned 2000 total points
ID: 40314263
If you don't want to have an error handling there, then just add "On Error Resume Next" to ignore possible errors.
.
.
.
On Error Resume Next
objOutput.Write strResults
 objOutput.Close

Open in new window

0
 

Author Comment

by:SimonJohnG
ID: 40314270
Hi Vitor,

Where would I place this?

Regards
S
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40314275
Should be in the line before you get the error. Should be line 13, right?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:SimonJohnG
ID: 40314492
Thank you but is there any method so the directory listing can continue? Say all files except those that cannot be successfully listed?
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40314502
Then I think you need to check for those exceptions in your EnumerateFolder procedure, inside the For Each objFile loop.
0
 

Author Comment

by:SimonJohnG
ID: 40314573
If only I knew how to do that which I don't.

Thank you  for the suggestion
0
 

Author Comment

by:SimonJohnG
ID: 40314710
Just noticed that the files are not invalid file names, they are filenames with Japanese characters, anyway of getting around this?

Regards
S
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40314723
Not really. Sorry.
0
 
LVL 12

Expert Comment

by:jkaios
ID: 40315897
Just noticed that the files are not invalid file names, they are filenames with Japanese characters, anyway of getting around this?

Since the OS doesn't allow naming a file with certain reserved characters (such as \/:*?""<>|) that's probably why you're getting that error.  So what you have to do is simply remove any of these chars from the fileaname before attempting to create the file.

Public Function removeCraps(ByVal sMyString, _
                            Optional ByVal CRAPS = "\/:*?""<>|", _
                            Optional ByVal sReplaceWith)
   
   Dim ii
   
   For ii = 1 To Len(CRAPS)
      sMyString = Replace(sMyString, Mid$(CRAPS, ii, 1), sReplaceWith)
   Next
   
   removeCraps = sMyString

End Function

Open in new window


Now, on line 13, simply:

strOutputFile = RemoveCraps(strOutputFile)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question