Invalid procedure call or argument

Indarnav
Indarnav used Ask the Experts™
on
below vbs code giving "Invalid procedure call or argument" error at line 93. pls guide.

'basic declarations
Const BIF_returnonlyfsdirs   = &H0001
Const BIF_dontgobelowdomain  = &H0002
Const BIF_statustext         = &H0004
Const BIF_returnfsancestors  = &H0008
Const BIF_editbox            = &H0010
Const BIF_validate           = &H0020
Const BIF_browseforcomputer  = &H1000
Const BIF_browseforprinter   = &H2000
Const BIF_browseincludesSourcePaths = &H4000
Dim drv,ssp,CDDrive,sDestinationPath, objFile
Dim fso, fld,homefolder 
 
 
 
setfol()
 
 
Sub setfol()
strComputer="."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive",,48)
 
For Each objItem In colItems
  colDrives = colDrives & "" & Replace(UCase(objItem.Drive), ":", "")
Next
MsgBox ("Your CD/DVD Drive letter is ")& colDrives & " " & "," & " " &("Please type it."),vbInformation,"CD/DVD Drive Letter"
Valid=False
 
Do
  strDrive = InputBox("Please Type Drive Letter for CD/DVD as displayed", "Select CD/DVD Drive", Strdrive)
  If Instr(colDrives, UCase(strDrive)) > 0 Then Valid=True
  If Trim(strdrive) = "" Then WScript.Quit 
  Loop Until Valid=True
MsgBox "Thanks for Typing Correct Alphabet " & strDrive,vbInformation,"Correct Drive"
 
 
Dim oFso : Set oFso = CreateObject("Scripting.FileSystemObject")
Set fso = CreateObject("Scripting.FileSystemObject")
homefolder = sDestinationPath
 
       ssp = Strdrive & ":\data"    '(\*.* to copy all)
 
 'calling folder selection function
  setdesti()
 
 'remove read only tag from destination folder.
 
NotReadOnly(HomeFolder)
 
 
  'select destination folder
 'copying code
Ofso.CopyFolder ssp,sDestinationPath,True 
Set fso = Nothing
 
End Sub
 
 
'2: selection for destination folder
sub setdesti()
 sDestinationPath = BrowseForFolder( _
        "Select a sDestinationPath or folder to copy", _
        BIF_returnonlyfsdirs , _
        "")
end sub
 
'3:browse folder function
 
Function BrowseForFolder(title, flag, dir)
    On Error Resume Next
    Dim oShell, oItem, tmp
    ' Create WshShell object.
    Set oShell = WScript.CreateObject("Shell.Application")
    ' Invoke Browse For Folder dialog box.
    Set oItem = oShell.BrowseForFolder(&H0, "Select Destination Folder/Folder ", flag, dir)
    ' Now we try to retrieve the full path.
    BrowseForFolder = oItem.ParentFolder.ParseName(oItem.Title).Path
    Set oShell = Nothing
    Set oItem = Nothing
    On Error GoTo 0
    End Function
    
    
'5: code for folder name
 
Sub NotReadOnly(FolderName)
 
    Dim fld, fil, sf
 
    Set fld = fso.GetFolder(FolderName)
    For Each fil In fld.Files
        fil.Attributes = 0
    Next
    For Each sf In fld.SubFolders
        NotReadOnly sf.Path
    Next
 
    Set fil = Nothing
    Set sf = Nothing
    Set fld = Nothing
 
End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Author of the Year 2009
Commented:
One possibility is that the error is actually on line 94 and your code is attempting to clear all attribute of a folder or an alias or a compressed file -- and that is disallowed.
To verify this, echo the filename to the screen just before executing that line.
If the error only occurs for folders or aliases or compressed files, then you will need to NOT set the attibutes to 0 for that item.

Author

Commented:
will it work if i remove notreadonly function?
Author of the Year 2009

Commented:
I don't know.  Did you try my suggestion?  Programming is all about trying different things to find out as much as you can about a problem.

Author

Commented:
i removed that function, as it is not required. it is working fine now. thanks for giving clue

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial