Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Help to copy files names in a column from one directory to another directory VBA

I have a list of picture names in a sheet named Search Results, Column C,
starting in C2, like DSCF0001, DSCF0002, ... that I want to copy them from
one directory to another directory, I have some code that will copy ALL the
pictures in the directory to the other one but how can I only copy the files
that are in column C. Here is the code to copy them all.

Thanks

Option Explicit
Sub CopyPictures()
Dim WSHShell As Object
Dim DesktopPath As String
Dim sSource As String
Dim sDestination As String
Dim fs As Object


Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set WSHShell = Nothing

'Checks to make sure you have the carousels folder
If Dir(Application.DefaultFilePath & "\My Pictures\Carousels\") =
vbNullString Then
MsgBox "Can Not Fine The Directory" & Application.DefaultFilePath & "\My
Pictures\Carousels", , "Directory Error"
Exit Sub
End If

'checks to see if you have the Copy of Carousels folder on your desktop
'if not it will be made
If Dir(DesktopPath & "\Copy of Carousels", vbDirectory) = vbNullString Then
MkDir DesktopPath & "\Copy of Carousels"

'use if you only want jpg files
'sSource = Application.DefaultFilePath _
& "\My Pictures\Carousels\*.jpg"

'use to get all files
sSource = Application.DefaultFilePath _
& "\My Pictures\Carousels\*"

'the destination folder
sDestination = DesktopPath & "\Copy of Carousels"

Set fs = CreateObject("Scripting.FileSystemObject")

fs.CopyFile sSource, sDestination

End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Help to copy files names in a column from one directory to another

I use something like this

FileCopy CurrentPath, newPath

Where CurrentPath is the FULL PATH for the file and NewPath is the full path
for it's new location
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Paul B" wrote:

I have a list of picture names in a sheet named Search Results, Column C,
starting in C2, like DSCF0001, DSCF0002, ... that I want to copy them from
one directory to another directory, I have some code that will copy ALL the
pictures in the directory to the other one but how can I only copy the files
that are in column C. Here is the code to copy them all.

Thanks

Option Explicit
Sub CopyPictures()
Dim WSHShell As Object
Dim DesktopPath As String
Dim sSource As String
Dim sDestination As String
Dim fs As Object


Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set WSHShell = Nothing

'Checks to make sure you have the carousels folder
If Dir(Application.DefaultFilePath & "\My Pictures\Carousels\") =
vbNullString Then
MsgBox "Can Not Fine The Directory" & Application.DefaultFilePath & "\My
Pictures\Carousels", , "Directory Error"
Exit Sub
End If

'checks to see if you have the Copy of Carousels folder on your desktop
'if not it will be made
If Dir(DesktopPath & "\Copy of Carousels", vbDirectory) = vbNullString Then
MkDir DesktopPath & "\Copy of Carousels"

'use if you only want jpg files
'sSource = Application.DefaultFilePath _
& "\My Pictures\Carousels\*.jpg"

'use to get all files
sSource = Application.DefaultFilePath _
& "\My Pictures\Carousels\*"

'the destination folder
sDestination = DesktopPath & "\Copy of Carousels"

Set fs = CreateObject("Scripting.FileSystemObject")

fs.CopyFile sSource, sDestination

End Sub





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Help to copy files names in a column from one directory to another

I don't see how this would work, or am I missing something?


"Barb Reinhardt" wrote in message
...
I use something like this

FileCopy CurrentPath, newPath

Where CurrentPath is the FULL PATH for the file and NewPath is the full
path
for it's new location
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Paul B" wrote:

I have a list of picture names in a sheet named Search Results, Column C,
starting in C2, like DSCF0001, DSCF0002, ... that I want to copy them
from
one directory to another directory, I have some code that will copy ALL
the
pictures in the directory to the other one but how can I only copy the
files
that are in column C. Here is the code to copy them all.

Thanks

Option Explicit
Sub CopyPictures()
Dim WSHShell As Object
Dim DesktopPath As String
Dim sSource As String
Dim sDestination As String
Dim fs As Object


Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set WSHShell = Nothing

'Checks to make sure you have the carousels folder
If Dir(Application.DefaultFilePath & "\My Pictures\Carousels\") =
vbNullString Then
MsgBox "Can Not Fine The Directory" & Application.DefaultFilePath & "\My
Pictures\Carousels", , "Directory Error"
Exit Sub
End If

'checks to see if you have the Copy of Carousels folder on your desktop
'if not it will be made
If Dir(DesktopPath & "\Copy of Carousels", vbDirectory) = vbNullString
Then
MkDir DesktopPath & "\Copy of Carousels"

'use if you only want jpg files
'sSource = Application.DefaultFilePath _
& "\My Pictures\Carousels\*.jpg"

'use to get all files
sSource = Application.DefaultFilePath _
& "\My Pictures\Carousels\*"

'the destination folder
sDestination = DesktopPath & "\Copy of Carousels"

Set fs = CreateObject("Scripting.FileSystemObject")

fs.CopyFile sSource, sDestination

End Sub







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help to copy files names in a column from one directory to anotherdirectory VBA

Option Explicit
sub testme()

Dim myOldPath as string
Dim myNewPath as string
dim myRng as range
dim myCell as range

myoldpath = "C:\somepathhere\"
mynewpath = "C:\someotherpathhere\"

with worksheets("search results")
set myrng = .range("C1",.cells(.rows.count,"C").end(xlup))
end with

for each mycell in myrng.cells
filecopy source:=myoldpath & mycell.value & ".jpg", _
destination:=mynewpath & mycell.value & ".jpg
next mycell

end sub

Untested and uncompiled. Watch out for typos.

(I added the extension (& ".jpg"). You may not need it.)

Paul B wrote:

I have a list of picture names in a sheet named Search Results, Column C,
starting in C2, like DSCF0001, DSCF0002, ... that I want to copy them from
one directory to another directory, I have some code that will copy ALL the
pictures in the directory to the other one but how can I only copy the files
that are in column C. Here is the code to copy them all.

Thanks

Option Explicit
Sub CopyPictures()
Dim WSHShell As Object
Dim DesktopPath As String
Dim sSource As String
Dim sDestination As String
Dim fs As Object

Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set WSHShell = Nothing

'Checks to make sure you have the carousels folder
If Dir(Application.DefaultFilePath & "\My Pictures\Carousels\") =
vbNullString Then
MsgBox "Can Not Fine The Directory" & Application.DefaultFilePath & "\My
Pictures\Carousels", , "Directory Error"
Exit Sub
End If

'checks to see if you have the Copy of Carousels folder on your desktop
'if not it will be made
If Dir(DesktopPath & "\Copy of Carousels", vbDirectory) = vbNullString Then
MkDir DesktopPath & "\Copy of Carousels"

'use if you only want jpg files
'sSource = Application.DefaultFilePath _
& "\My Pictures\Carousels\*.jpg"

'use to get all files
sSource = Application.DefaultFilePath _
& "\My Pictures\Carousels\*"

'the destination folder
sDestination = DesktopPath & "\Copy of Carousels"

Set fs = CreateObject("Scripting.FileSystemObject")

fs.CopyFile sSource, sDestination

End Sub


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Help to copy files names in a column from one directory to another directory VBA

Dave, thanks for the help, have it working now

"Dave Peterson" wrote in message
...
Option Explicit
sub testme()

Dim myOldPath as string
Dim myNewPath as string
dim myRng as range
dim myCell as range

myoldpath = "C:\somepathhere\"
mynewpath = "C:\someotherpathhere\"

with worksheets("search results")
set myrng = .range("C1",.cells(.rows.count,"C").end(xlup))
end with

for each mycell in myrng.cells
filecopy source:=myoldpath & mycell.value & ".jpg", _
destination:=mynewpath & mycell.value & ".jpg
next mycell

end sub

Untested and uncompiled. Watch out for typos.

(I added the extension (& ".jpg"). You may not need it.)

Paul B wrote:

I have a list of picture names in a sheet named Search Results, Column C,
starting in C2, like DSCF0001, DSCF0002, ... that I want to copy them
from
one directory to another directory, I have some code that will copy ALL
the
pictures in the directory to the other one but how can I only copy the
files
that are in column C. Here is the code to copy them all.

Thanks

Option Explicit
Sub CopyPictures()
Dim WSHShell As Object
Dim DesktopPath As String
Dim sSource As String
Dim sDestination As String
Dim fs As Object

Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set WSHShell = Nothing

'Checks to make sure you have the carousels folder
If Dir(Application.DefaultFilePath & "\My Pictures\Carousels\") =
vbNullString Then
MsgBox "Can Not Fine The Directory" & Application.DefaultFilePath & "\My
Pictures\Carousels", , "Directory Error"
Exit Sub
End If

'checks to see if you have the Copy of Carousels folder on your desktop
'if not it will be made
If Dir(DesktopPath & "\Copy of Carousels", vbDirectory) = vbNullString
Then
MkDir DesktopPath & "\Copy of Carousels"

'use if you only want jpg files
'sSource = Application.DefaultFilePath _
& "\My Pictures\Carousels\*.jpg"

'use to get all files
sSource = Application.DefaultFilePath _
& "\My Pictures\Carousels\*"

'the destination folder
sDestination = DesktopPath & "\Copy of Carousels"

Set fs = CreateObject("Scripting.FileSystemObject")

fs.CopyFile sSource, sDestination

End Sub


--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Excel Files to new directory Ray Clark[_2_] Excel Programming 3 April 18th 07 11:58 PM
Creating a macro that lists directory names within a directory.... Andy Excel Programming 4 November 28th 04 06:13 AM
Check if directory empty OR no of files in directory. Michael Beckinsale Excel Programming 2 December 4th 03 10:12 PM
find files and copy to new directory arne Excel Programming 3 November 26th 03 07:26 PM
Copy range of many files in directory. CLUPE Excel Programming 1 July 15th 03 04:37 PM


All times are GMT +1. The time now is 05:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"