Help using FileSystemObject CopyFile

T

Tod

I have this code in a workbook:

Sub Main()
Dim filesys As Object
Dim objNet As Object
Dim ReportDate As String
Dim ReportsFolder As String

ReportsFolder = "C:\MyPath\"

Set objNet = CreateObject("WScript.Network")
objNet.MapNetworkDrive LocalName:="L:",
RemoteName:="\\NetworkPath\NetworkFolder",
UserName:="MyUserName", Password:="mypassword"

Set filesys = CreateObject
("Scripting.FileSystemObject")
If filesys.fileexists(ReportsFolder & "FileName.xls")
Then _
filesys.copyfile ReportsFolder
& "FileName.xls", "L:\FileName.xls"

objNet.RemoveNetworkDrive "L:"

End Sub

If I open the workbook and run the procedure manually, it
works. If I create a vbscript to open the workbook and run
the procedure, it also works. However, if I create a
scheduled task to run the script, it gets as far as
opening the workbook. But then the workbook just stays
open in memory. No file gets copied. I have to end task on
Excel.

Can someone help me with this?

tod
 
B

Bob Phillips

Is the Excel workbook throwing up a message that doesn't get responded to
when running as a scheduled task?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top