Moving contents of folder  
Author Message
Rowena-NW





PostPosted: Mon Jul 24 08:13:31 CDT 2006 Top

MS Word VBA >> Moving contents of folder

Please can someone assist with this problem?

I am using the following code with I got from the newsgroups which moves
files from one location to another.

Sub MoveForPrint()
Dim i As Integer
Dim Response As Integer, TotalFiles As Integer
Dim counter As Integer

On Error Resume Next

'This part of the routine copies all files and subfolders from sFolder to
sPrintFolder.
'Note: If sPrintFolder already exist it will overwrite existing files in
this folder
'if sPrintFolder not exist it will be made for you.

'test locations
'sFolder = "C:\Orig" '<< Change
'sPrintFolder = "C:\Destination\ToPrint" '<< Change

'U Drive test
'sFolder = "U:\WT Business Services\Print Unit\Victim Letters"
'<< Change
'sPrintFolder = "U:\WT Business Services\Print Unit\Victim
Letters\ToPrint" '<< Change

sFolder = "U:\EA Kirklees\Management Support\Victims\Victim Letters"
'<< Change
sPrintFolder = "U:\EA Kirklees\Management Support\Victims\Victim
Letters\ToPrint" '<< Change

'If you want to create a backup of your folder every time you run this
macro
'you can create a unique folder with a Date/Time stamp.
'sPrintFolder = "C:\" & Format(Now, "dd-mmm-yy h-mm-ss")

If Right(sFolder, 1) = "\" Then
sFolder = Left(sFolder, Len(sFolder) - 1)
End If

If Right(sPrintFolder, 1) = "\" Then
sPrintFolder = Left(sPrintFolder, Len(sPrintFolder) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(sFolder) = False Then
MsgBox sFolder & " doesn't exist"
Exit Sub
End If

FSO.CopyFolder Source:=sFolder, Destination:=sPrintFolder
'MsgBox "You can find the files and subfolders from " & sFolder & " in "
& sPrintFolder

MsgBox ("The documents have been moved for printing."), vbInformation, ""

End Sub


The code works fine on the 'C:\Drive but when I run it on the network drives
it seems to work, but it removes the files form the original location and
looses all the files!

I have checked the filepaths and they seem to be correct!

Can someone assist me with a solution whether it be a alteration to this
code or an alternative, please?
--
Mark

Word80  
 
 
Jonathan





PostPosted: Mon Jul 24 08:13:31 CDT 2006 Top

MS Word VBA >> Moving contents of folder Remove or comment out the "On Error Resume next" line, run the macro again,
and let us know what line it stops on and what the error message is.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org



> Please can someone assist with this problem?
>
> I am using the following code with I got from the newsgroups which moves
> files from one location to another.
>
> Sub MoveForPrint()
> Dim i As Integer
> Dim Response As Integer, TotalFiles As Integer
> Dim counter As Integer
>
> On Error Resume Next
>
> 'This part of the routine copies all files and subfolders from sFolder to
> sPrintFolder.
> 'Note: If sPrintFolder already exist it will overwrite existing files in
> this folder
> 'if sPrintFolder not exist it will be made for you.
>
> 'test locations
> 'sFolder = "C:\Orig" '<< Change
> 'sPrintFolder = "C:\Destination\ToPrint" '<< Change
>
> 'U Drive test
> 'sFolder = "U:\WT Business Services\Print Unit\Victim Letters"
> '<< Change
> 'sPrintFolder = "U:\WT Business Services\Print Unit\Victim
> Letters\ToPrint" '<< Change
>
> sFolder = "U:\EA Kirklees\Management Support\Victims\Victim Letters"
> '<< Change
> sPrintFolder = "U:\EA Kirklees\Management Support\Victims\Victim
> Letters\ToPrint" '<< Change
>
> 'If you want to create a backup of your folder every time you run this
> macro
> 'you can create a unique folder with a Date/Time stamp.
> 'sPrintFolder = "C:\" & Format(Now, "dd-mmm-yy h-mm-ss")
>
> If Right(sFolder, 1) = "\" Then
> sFolder = Left(sFolder, Len(sFolder) - 1)
> End If
>
> If Right(sPrintFolder, 1) = "\" Then
> sPrintFolder = Left(sPrintFolder, Len(sPrintFolder) - 1)
> End If
>
> Set FSO = CreateObject("scripting.filesystemobject")
>
> If FSO.FolderExists(sFolder) = False Then
> MsgBox sFolder & " doesn't exist"
> Exit Sub
> End If
>
> FSO.CopyFolder Source:=sFolder, Destination:=sPrintFolder
> 'MsgBox "You can find the files and subfolders from " & sFolder & " in
> "
> & sPrintFolder
>
> MsgBox ("The documents have been moved for printing."), vbInformation,
> ""
>
> End Sub
>
>
> The code works fine on the 'C:\Drive but when I run it on the network
> drives
> it seems to work, but it removes the files form the original location and
> looses all the files!
>
> I have checked the filepaths and they seem to be correct!
>
> Can someone assist me with a solution whether it be a alteration to this
> code or an alternative, please?
> --
> Mark

 
 
Mark





PostPosted: Mon Jul 24 08:27:02 CDT 2006 Top

MS Word VBA >> Moving contents of folder It's debugging on this line

FSO.CopyFolder Source:=sFolder, Destination:=sPrintFolder

--
Mark




> Remove or comment out the "On Error Resume next" line, run the macro again,
> and let us know what line it stops on and what the error message is.
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
>


> > Please can someone assist with this problem?
> >
> > I am using the following code with I got from the newsgroups which moves
> > files from one location to another.
> >
> > Sub MoveForPrint()
> > Dim i As Integer
> > Dim Response As Integer, TotalFiles As Integer
> > Dim counter As Integer
> >
> > On Error Resume Next
> >
> > 'This part of the routine copies all files and subfolders from sFolder to
> > sPrintFolder.
> > 'Note: If sPrintFolder already exist it will overwrite existing files in
> > this folder
> > 'if sPrintFolder not exist it will be made for you.
> >
> > 'test locations
> > 'sFolder = "C:\Orig" '<< Change
> > 'sPrintFolder = "C:\Destination\ToPrint" '<< Change
> >
> > 'U Drive test
> > 'sFolder = "U:\WT Business Services\Print Unit\Victim Letters"
> > '<< Change
> > 'sPrintFolder = "U:\WT Business Services\Print Unit\Victim
> > Letters\ToPrint" '<< Change
> >
> > sFolder = "U:\EA Kirklees\Management Support\Victims\Victim Letters"
> > '<< Change
> > sPrintFolder = "U:\EA Kirklees\Management Support\Victims\Victim
> > Letters\ToPrint" '<< Change
> >
> > 'If you want to create a backup of your folder every time you run this
> > macro
> > 'you can create a unique folder with a Date/Time stamp.
> > 'sPrintFolder = "C:\" & Format(Now, "dd-mmm-yy h-mm-ss")
> >
> > If Right(sFolder, 1) = "\" Then
> > sFolder = Left(sFolder, Len(sFolder) - 1)
> > End If
> >
> > If Right(sPrintFolder, 1) = "\" Then
> > sPrintFolder = Left(sPrintFolder, Len(sPrintFolder) - 1)
> > End If
> >
> > Set FSO = CreateObject("scripting.filesystemobject")
> >
> > If FSO.FolderExists(sFolder) = False Then
> > MsgBox sFolder & " doesn't exist"
> > Exit Sub
> > End If
> >
> > FSO.CopyFolder Source:=sFolder, Destination:=sPrintFolder
> > 'MsgBox "You can find the files and subfolders from " & sFolder & " in
> > "
> > & sPrintFolder
> >
> > MsgBox ("The documents have been moved for printing."), vbInformation,
> > ""
> >
> > End Sub
> >
> >
> > The code works fine on the 'C:\Drive but when I run it on the network
> > drives
> > it seems to work, but it removes the files form the original location and
> > looses all the files!
> >
> > I have checked the filepaths and they seem to be correct!
> >
> > Can someone assist me with a solution whether it be a alteration to this
> > code or an alternative, please?
> > --
> > Mark
>
>
 
 
Jonathan





PostPosted: Mon Jul 24 09:01:06 CDT 2006 Top

MS Word VBA >> Moving contents of folder


> It's debugging on this line
>
> FSO.CopyFolder Source:=sFolder, Destination:=sPrintFolder
>


And the error message is?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

 
 
Mark





PostPosted: Mon Jul 24 09:07:01 CDT 2006 Top

MS Word VBA >> Moving contents of folder
Runtime error 5
Invalid procedure call or argument

--
Mark




>


> > It's debugging on this line
> >
> > FSO.CopyFolder Source:=sFolder, Destination:=sPrintFolder
> >
>
>
> And the error message is?
>
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
>
>