View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Michael McClellan Michael McClellan is offline
external usenet poster
 
Posts: 15
Default Move files from one directory to another: if they are there



Hmm. When I change the filename manually to "HMA4114" this whole thing
works. LIKE A CHARM. But I need the directory to be in the form of a
variable so it can sift through all the files. Here is what I did.

Could it have something to do with the variable types of CurrFile or
DimVar2?

Sub FileScanned()
'
' FileScanned Macro
' Macro recorded 6/23/2004 by Michael McClellan, Jr.
'

'
Dim DirVar1 As String
Dim DirVar2 As String
Dim DirVar3 As String
Dim DirVar4 As String

Dim CurrDir As String
Dim CurrFile As String

Dim rownum As Integer
Dim FilesFiled As Integer

Sheets("Orders").Select
FilesFiled = 0
rownum = 7
Do

DirVar1 = Range("A" & rownum).Value 'office code
DirVar2 = Range("B" & rownum).Value 'HM PO#
DirVar3 = Range("F" & rownum).Value 'vendor code
DirVar4 = Range("L" & rownum).Value 'customer po

CurrDir = "HM" & DirVar1 & DirVar2 & " - " & DirVar3 & " - " &
DirVar4
CurrFile = "HMA4114" '"HM" & DirVar1 & DirVar2

Set fs = CreateObject("Scripting.FileSystemObject")
If Dir("C:\Ricoh Scan Files\*" & CurrFile & ".pdf") < "" Then
'If fs.FileExists("C:\Ricoh Scan Files\*HMB4129.pdf") = True Then
'On Error GoTo ErrHandler:
fs.MoveFile "C:\Ricoh Scan Files\*" & CurrFile & ".pdf",
"R:\Orders\" & CurrDir & "\"
FilesFiled = FilesFiled + 1
End If

'ReturnToMacro:
rownum = rownum + 1
'Exit Sub

'error handling routine
'ErrHandler:
'Resume ReturnToMacro

Loop Until DirVar2 = ""
MsgBox FilesFiled & " files were filed."

End Sub


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!