filecopy help

thescottsman92

Registered User.
Local time
Today, 21:28
Joined
Sep 2, 2013
Messages
24
Hi

I have a problem in the copyfile function. It says "CompileError - Expected =" and I am not sure if im even setting this correctly. This is my cde:

Dim fso As Object
Set fso = VBA.CreateObject(filesystemobject)
fso.copyfile(me.txtPath,me.txtarchivepath & me.txtnewfile)

I think the problem is the "filesystemobject bit in the code

can anyone please help me

thanks very much
 
try
Set fso = VBA.CreateObject("scripting.filesystemobject")
 
Hello thescottsman92, Welcome to AWF.. :)

Try just..
Code:
FileCopy Me.txtPath, Me.txtArchivePath & Me.txtNewFile
I would also check if the Directory exists before making the copy..
 
Hi

Thanks for your speedy replys

I have tried just the single line and I am getting error 53, file not found.

The file diffinatly exists so not sure where to go now

thans
 
I have also tried using what CJ suggested and still no luck

this is what I have now

Dim fso As Object
Set fso = VBA.CreateObject(scripting.filesystemobject)
fso.copyfile("me.txtPath","me.txtarchivepath & me.txtnewfile")
 
check my original post - scripting.filesystemobject should be surrounded with double quotation marks
 
So am I guessing you are trying to copy a File from one location to another? Try debugging..
Code:
MsgBox Me.txtPath            [COLOR=Green]'This should pop up something like N:\CarynQuery.xlsx[/COLOR]
MsgBox Me.txtNewFile        [COLOR=Green]'This should pop up something like HaHaCarynQuery.xlsx[/COLOR]
MsgBox Me.txtArchivePath   [COLOR=Green] 'This should pop up something like N:\DONOT CHANGE\[/COLOR]
[COLOR=Green]'FileCopy Me.txtPath, Me.txtArchivePath & Me.txtNewFile[/COLOR]
 
Thanks for much for all your time and effiort in helping me

I have put this in now and I am now getting a syntax error on the line:

fso.copyfile("me.txtPath","me.txtarchivepath & me.txtnewfile")
 
You should not surround variables with Quotes.. It should be..
Code:
fso.CopyFile(Me.txtPath, Me.txtArchivePath & Me.txtNewFile)
 
Hi thanks for all your help

through the combination of everyones copontribution I have worked it out

It was also part of me misspelling something (I feel such an idiot)

thanks for all your help :)
 
that is because you have quotations and don't need them:

fso.copyfile(me.txtPath,me.txtarchivepath & me.txtnewfile)

However given the error you are getting this is almost certainly either your me.txtPath does not exist or this construct me.txtarchivepath & me.txtnewfile does not exist or is missing a "\"

Pauls suggestion of FileCopy will achieve the same thing and I would follow his advice re tracing down the problem
 

Users who are viewing this thread

Back
Top Bottom