Dear All,
I am using the coding below to find a file in dfile and save it in pathname. is there a way to find the file in dfile if dfile has 2 numbers in front of it.
Sheets("Personal"
.Select
dfile = "M:\Templates\Saved Files\"
efile = "*all_work_summary.csv"
'the same line split down
pathname = "C:\Rob\Test\" & _
Format(Range("c2"
.value, "mmmm"
& "\" & _
Format(Range("c2"
.value, "dd.mm"
& ".xls"
'to here
pathname1 = Format(Range("c2"
.value, "dd.mm"
& ".xls"
ChDir dfile
'checks the location to see if file exists
sfile = dfile & efile
sfile1 = Dir(sfile)
sfile2 = dfile & sfile1
If sfile1 <> "" Then ' if the file exists it opens and saves as .xls
Workbooks.Open Filename:=sfile2
ActiveWorkbook.SaveAs Filename:=pathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
' then closes the file
Application.CutCopyMode = False
ActiveWindow.Close
' displays a message advising file opened and saved to disk
MsgBox "File " & sfile1 & " was found and saved to disk" _
& " as " & pathname1, vbInformation
Kill sfile2
Mainform.Show
Else
' displays a message saying file does not exist in location.
MsgBox "File " & sfile & " is not in location", vbExclamation
Mainform.Show
End If
Thanks Rob.![[yoda] [yoda] [yoda]](/data/assets/smilies/yoda.gif)
I am using the coding below to find a file in dfile and save it in pathname. is there a way to find the file in dfile if dfile has 2 numbers in front of it.
Sheets("Personal"
dfile = "M:\Templates\Saved Files\"
efile = "*all_work_summary.csv"
'the same line split down
pathname = "C:\Rob\Test\" & _
Format(Range("c2"
Format(Range("c2"
'to here
pathname1 = Format(Range("c2"
ChDir dfile
'checks the location to see if file exists
sfile = dfile & efile
sfile1 = Dir(sfile)
sfile2 = dfile & sfile1
If sfile1 <> "" Then ' if the file exists it opens and saves as .xls
Workbooks.Open Filename:=sfile2
ActiveWorkbook.SaveAs Filename:=pathname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
' then closes the file
Application.CutCopyMode = False
ActiveWindow.Close
' displays a message advising file opened and saved to disk
MsgBox "File " & sfile1 & " was found and saved to disk" _
& " as " & pathname1, vbInformation
Kill sfile2
Mainform.Show
Else
' displays a message saying file does not exist in location.
MsgBox "File " & sfile & " is not in location", vbExclamation
Mainform.Show
End If
Thanks Rob.
![[yoda] [yoda] [yoda]](/data/assets/smilies/yoda.gif)