ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   FileSystemObject.copyfile (https://www.excelbanter.com/excel-programming/363823-filesystemobject-copyfile.html)

KR

FileSystemObject.copyfile
 

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



[email protected]

FileSystemObject.copyfile
 
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



Charlie

FileSystemObject.copyfile
 
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




Charlie

FileSystemObject.copyfile
 
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




Charlie

FileSystemObject.copyfile
 
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



KR

FileSystemObject.copyfile
 
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





Charlie

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






KR

FileSystemObject.copyfile
 
Before I got your response, I kept trying, and finally found a similar
solution from an old post; they used:
Set FSO = CreateObject("Scripting.FileSystemObject")
Which seems to work even without the reference. I'll check the reference
just for future use, and it looks like I'm good to go!
Thanks again for all the help!!
Keith

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





All times are GMT +1. The time now is 12:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com