Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tod tod is offline
external usenet poster
 
Posts: 114
Default Help using FileSystemObject CopyFile

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Help using FileSystemObject CopyFile

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)

"Tod" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileSystemObject lol[_2_] Excel Programming 2 April 6th 04 09:56 PM
FileSystemObject Error AlexJ Excel Programming 3 February 29th 04 10:00 PM
CopyFile usage Garry[_5_] Excel Programming 1 January 19th 04 08:56 PM
FileSystemObject CopyFile with UserID/Password Tod[_3_] Excel Programming 0 January 7th 04 06:03 PM
Help with FileSystemObject? Ed[_9_] Excel Programming 2 August 5th 03 12:08 AM


All times are GMT +1. The time now is 07:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"