View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Charlie Charlie is offline
external usenet poster
 
Posts: 703
Default FileSystemObject.copyfile

You need the Microsoft Scripting Runtime library. From your VBE window do:

Tools--References

(it might take a moment to open). Then scroll down to find the library and
click the checkbox (don't just highlight the line.) Click Ok.

"KR" wrote:

I incorporated both suggestion, and my code snippet is now:

CopySource = RnRPath & WorkingFiles & RnRTemplate
CopyDestination = RnRPath & LanID & ".xls"
Dim FSO As New filesystemobject
FSO.CopyFile CopySource, CopyDestination

Both strings are concatenating properly, but....
I think this has identified an underlying problem that isn't mentioned in
the help file; The concatenation still works, but I'm getting a compile
error on the Dim FSO as New FileSystemObject line- and as you can see above,
it doesn't autorecognize the word and add the caps (FileSystemObject vs
filesystemobject).

Does the use of a FileSystemObject require a reference setting? I don't have
any missing references listed, but I'm not sure why else I wouldn't be able
to reference a filesystem object. Using XL2003 on Win2000

Thanks,
Keith

"Charlie" wrote in message
...
and

Dim FSO as New FileSystemObject

for some reason need "New"

"Charlie" wrote:

Sorry, it's not a space after the ".xls" it's a comma

FSO.CopyFile _
RnRPath & WorkingFiles & RnRTemplate, _
RnRPath & ".xls", DestFileName

"Charlie" wrote:

Maybe try:

Dim FSO as FileSystemObject
'then do:
FSO.CopyFile

'AND you need a destination filename

FSO.CopyFile _
RnRPath & WorkingFiles & RnRTemplate, _
RnRPath & ".xls " & DestFileName '(note the trailing space after

..xls)

'(But I don't know about that LanID part, I removed it)


" wrote:

It looks OK, so it MIGHT be worth storing the strings in variables

and
using those rather than getting the CopyFile to concatenate.

KR wrote:
I'm using the following:

FileSystemObject.CopyFile _
RnRPath & WorkingFiles & RnRTemplate, _
RnRPath & LanID & ".xls"

and getting a runtime 424 object required error.

RnRPath is a network path, e.g. "\\server\folder\"
WorkingFiles is just a subfolder, e.g. "subfolder\"
RnRTemplate is a filename, e.g. "MyFile.xls"
And LanID is the user's login ID string, e.g. "myname"

I've checked the string assignments for the above variables, and

they point
to a file and directory that exists.... Is there something else I

should be
checking, or is it likely to be something about the paths and

filename that
I'm not seeing? I have network access to all of these areas and

use these
files 'manually', just can't seem to get it working in code.

Thanks!
Keith