Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Move and delete files

I would like to cascade down through my worksheet from top to the end and
process the data as follows. In column A I have a filename, I will have a
constant source folder identified (ie. c:\input) and target folder identified
(ie. c:\output).

Column A
test1.txt
test2.txt
test3.txt

I would like to verify the file actually exists and IF it does then move it
to the destination folder and delete the file. If the file does NOT exist
then possibly highlight that cell so it can be removed from the worksheet.

I had a function that checks the file but all UDF are no longer working. I
use Excel 2007. Any help would be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Move and delete files

Try this

Public Sub MoveFiles(ByVal Source As String, ByVal Destination As String)
Dim oFSO As Object


Set oFSO = CreateObject("Scripting.FileSystemObject")

With oFSO
If .FileExists(Source) Then
.MoveFile Source, Destination
Else
MsgBox Source & " Doesn't Exist", vbExclamation
End If
End With
Set oFSO = Nothing
End Sub

Sub RunThroughList()
Dim I As Long
Dim Destination As String
Dim Lastrow As Long

Lastrow = Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row

For I = 1 To Lastrow
MoveFiles Range("A" & I).Value, "C:\Documents and Settings\My Documents\"

Next
End Sub




"Rookie_User" wrote:

I would like to cascade down through my worksheet from top to the end and
process the data as follows. In column A I have a filename, I will have a
constant source folder identified (ie. c:\input) and target folder identified
(ie. c:\output).

Column A
test1.txt
test2.txt
test3.txt

I would like to verify the file actually exists and IF it does then move it
to the destination folder and delete the file. If the file does NOT exist
then possibly highlight that cell so it can be removed from the worksheet.

I had a function that checks the file but all UDF are no longer working. I
use Excel 2007. Any help would be appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Move and delete files

Does this automatically assume a default source folder? Because the file
does exist and it keeps going past the move part. The filename is in column
A, and I wasn't sure where to put the source folder value, not unlike how you
have the destination folder set?

Currently it keeps saying the file doesn't exist, when it does.
Additionally I am a little confused when using the ofs type stuff, but thank
you for your time and effort. I am close but not quite there.

"Jeff" wrote:

Try this

Public Sub MoveFiles(ByVal Source As String, ByVal Destination As String)
Dim oFSO As Object


Set oFSO = CreateObject("Scripting.FileSystemObject")

With oFSO
If .FileExists(Source) Then
.MoveFile Source, Destination
Else
MsgBox Source & " Doesn't Exist", vbExclamation
End If
End With
Set oFSO = Nothing
End Sub

Sub RunThroughList()
Dim I As Long
Dim Destination As String
Dim Lastrow As Long

Lastrow = Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row

For I = 1 To Lastrow
MoveFiles Range("A" & I).Value, "C:\Documents and Settings\My Documents\"

Next
End Sub




"Rookie_User" wrote:

I would like to cascade down through my worksheet from top to the end and
process the data as follows. In column A I have a filename, I will have a
constant source folder identified (ie. c:\input) and target folder identified
(ie. c:\output).

Column A
test1.txt
test2.txt
test3.txt

I would like to verify the file actually exists and IF it does then move it
to the destination folder and delete the file. If the file does NOT exist
then possibly highlight that cell so it can be removed from the worksheet.

I had a function that checks the file but all UDF are no longer working. I
use Excel 2007. Any help would be appreciated.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Move and delete files

I inserted the full path in column A and was getting it closer but it errors
by saying a file already exists when it attempts the move? I put watches on
the values and the destination is accurate and the file does not exist there,
any idea's?

"Jeff" wrote:

Try this

Public Sub MoveFiles(ByVal Source As String, ByVal Destination As String)
Dim oFSO As Object


Set oFSO = CreateObject("Scripting.FileSystemObject")

With oFSO
If .FileExists(Source) Then
.MoveFile Source, Destination
Else
MsgBox Source & " Doesn't Exist", vbExclamation
End If
End With
Set oFSO = Nothing
End Sub

Sub RunThroughList()
Dim I As Long
Dim Destination As String
Dim Lastrow As Long

Lastrow = Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row

For I = 1 To Lastrow
MoveFiles Range("A" & I).Value, "C:\Documents and Settings\My Documents\"

Next
End Sub




"Rookie_User" wrote:

I would like to cascade down through my worksheet from top to the end and
process the data as follows. In column A I have a filename, I will have a
constant source folder identified (ie. c:\input) and target folder identified
(ie. c:\output).

Column A
test1.txt
test2.txt
test3.txt

I would like to verify the file actually exists and IF it does then move it
to the destination folder and delete the file. If the file does NOT exist
then possibly highlight that cell so it can be removed from the worksheet.

I had a function that checks the file but all UDF are no longer working. I
use Excel 2007. Any help would be appreciated.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Move and delete files

Your original code worked above but I had to put in the full path in column A
and also when I declared my output path it required a "\" at the end.

Thank you!!!

"Rookie_User" wrote:

I inserted the full path in column A and was getting it closer but it errors
by saying a file already exists when it attempts the move? I put watches on
the values and the destination is accurate and the file does not exist there,
any idea's?

"Jeff" wrote:

Try this

Public Sub MoveFiles(ByVal Source As String, ByVal Destination As String)
Dim oFSO As Object


Set oFSO = CreateObject("Scripting.FileSystemObject")

With oFSO
If .FileExists(Source) Then
.MoveFile Source, Destination
Else
MsgBox Source & " Doesn't Exist", vbExclamation
End If
End With
Set oFSO = Nothing
End Sub

Sub RunThroughList()
Dim I As Long
Dim Destination As String
Dim Lastrow As Long

Lastrow = Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row

For I = 1 To Lastrow
MoveFiles Range("A" & I).Value, "C:\Documents and Settings\My Documents\"

Next
End Sub




"Rookie_User" wrote:

I would like to cascade down through my worksheet from top to the end and
process the data as follows. In column A I have a filename, I will have a
constant source folder identified (ie. c:\input) and target folder identified
(ie. c:\output).

Column A
test1.txt
test2.txt
test3.txt

I would like to verify the file actually exists and IF it does then move it
to the destination folder and delete the file. If the file does NOT exist
then possibly highlight that cell so it can be removed from the worksheet.

I had a function that checks the file but all UDF are no longer working. I
use Excel 2007. Any help would be appreciated.

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
Delete Rows then Move Up Gordon[_2_] Excel Programming 8 September 30th 06 08:50 AM
Delete and Move Up Gordon[_2_] Excel Programming 4 September 29th 06 04:00 PM
Selecting every other row to delete or move Jeanne Excel Discussion (Misc queries) 1 April 8th 06 01:53 AM
Move text after delete gregork Excel Programming 3 December 9th 04 09:20 AM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM


All times are GMT +1. The time now is 01:04 AM.

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

About Us

"It's about Microsoft Excel"