mrfitness


I am not sure why I am getting an error, maybe someone can help figure this out I have used the code before and it works fine, it copied an excel sheet from the server and pasted it into the folder I was working in and renamed it.

I am trying to copy an excel book that its purpose is simply being a blank book to copy and populate values in. I am using a variable to name the new excel book. I am using SYS values to grab the path. In my code I am printing the values in the background with ' ' so I can see the variables I am using and they appear fine. Yet I get an error on my COPY FILE ....TO... line of coding - "Command contains unrecognized phrase/keyword"

Below are samples of the code:

sele 1
use foxytest
select contractno from foxytest group by 1 into table contract
close all

sDir = SYS(5)+SYS(2003)+ "\"

sele 1
use foxytest

sele 2
use contract

scan
a = alltrim(contractno)
lcFileName = (sDir + "ship_" + a + ".XLS")
............
..........
Copy File "C:\Documents and Settings\NPico\Desktop\Book1.xls" To &lcFileName




Re: 'Copy File to' command using variables

Naomi Nosonovsky


Try

Copy File "C:\Documents and Settings\NPico\Desktop\Book1.xls" To (m.lcFileName)

E.g. use name expression instead of the macro. Macro will fail in case of spaces in the directory name and it is not needed in this situation at all.

Also don't use SELECT 1, SELECT2, etc., always use SELECT 0

Otherwise somebody who will need to maintain this code later may have some problems Smile






Re: 'Copy File to' command using variables

hangover

It is probably because your file path (i.e. SYS(2003)) has a space in it. Try the following instead

Code Snippet

Copy File "C:\Documents and Settings\NPico\Desktop\Book1.xls" To (lcFileName)

Dom





Re: 'Copy File to' command using variables

mrfitness

You are correct, the spaces did mess things up (I was thinking it had to do with that)
The brackets fixed it. Thanks!

hangover wrote:

It is probably because your file path (i.e. SYS(2003)) has a space in it. Try the following instead

Code Snippet

Copy File "C:\Documents and Settings\NPico\Desktop\Book1.xls" To (lcFileName)

Dom