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
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