views:

98

answers:

2

I'm trying to run the below mentioned code in VB(Excel Macro) but i m stuck with an error which pops up on running saying "Automation Error".

strComputer = "."

Set objNetwork = CreateObject("Wscript.Network") Set fs = CreateObject("Scripting.FileSystemObject")

Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2") Set colFiles = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='U:\'} Where " _ & "ResultClass = CIM_DataFile")

For Each objFile In colFiles if objFile.FileName = "ml_*" Then

       destinationPROD = "X:\ABC\" & objFile.FileName & "." & objFile.Extension
       objFile.Copy(destinationPROD)

       objFile.delete

   else

       destinationPROD = "X:\PQR\" & objFile.FileName & "." & objFile.Extension
       objFile.Copy(destinationPROD)


       objFile.delete

   End If

Next

Thanks in advance.Please help me

A: 

It might be a rights problem. Test it using a local disk. Make sure that all required directories exist.

Shiraz Bhaiji
+1  A: 

You just need another slash after "winmgmts:\" :)

It should be:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Oorang