part 2

oldFile = toreportftppath & reportpdf
newPath = toDoctorFolderPath & Format(Date, "YYYY-MM-DD")
newFile = newPath & "\" & reportpdf
strdir = toDoctorFolderPath


If Dir(newPath, vbDirectory) = "" Then
MkDir newPath
End If

Set fso = CreateObject("Scripting.FilesystemObject")

If fso.FolderExists(Reportbufolder) = False Then
vbf = MsgBox("Folder not created. Created " & formatyyyymmdd & " folder?", vbOKCancel)

If vbf = vbOK Then
fso.CreateFolder (Reportbufolder)
ElseIf vbf = vbCancel Then
Exit Sub
End If

End If

If fso.FileExists(reportbupath) = False Then

WDDoc.SaveAs reportbupath

WDDoc.ExportAsFixedFormat OutputFileName:= _
Reportbufolder & WDDoc.FormFields("NRIC").Result & "_" & formatDDMMYY & ".pdf", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False


ElseIf fso.FileExists(reportbupath) = True Then
vb = MsgBox("Copy already present in server. Do you want to continue overwriting the file?", vbOKCancel)

If vb = vbOK Then
WDDoc.SaveAs reportbupath
WDDoc.ExportAsFixedFormat OutputFileName:= _
Reportbufolder & WDDoc.FormFields("NRIC").Result & "_" & formatDDMMYY & ".pdf", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
ElseIf vb = vbCancel Then
Sheets(sheetname).Select
Exit Sub
End If

End If

Dim ImageFromFTPPath As String
Dim Imagetobupath As String
Dim count As Integer
ImageFromFTPPath = "H:\IN\" 'HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Imagetobupath = "Z:\SGH Diabetes Centre\Images\" & Format(Date, "YYYY") & "\" & formatyyyymmdd & "\" ' HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Set FSOobj = CreateObject("Scripting.FilesystemObject")

If FSOobj.FolderExists(Imagetobupath) = False Then
vbf = MsgBox("Folder not created. Created " & formatyyyymmdd & " folder?", vbOKCancel)
If vbf = vbOK Then
FSOobj.CreateFolder (Imagetobupath)
ElseIf vb = vbCancel Then
Exit Sub

End If
End If

If fso.FileExists(toreportftppath & reportpdf) = False Then
'WDDoc.SaveAs toreportftppath & reportname
WDDoc.Activate

WDDoc.ExportAsFixedFormat OutputFileName:= _
toreportftppath & reportpdf, ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False

ElseIf fso.FileExists(toreportftppath & reportpdf) = True Then
vb = MsgBox("Copy already present in FTP. Do you want to continue overwriting the file?", vbOKCancel)

If vb = vbOK Then
'WDDoc.SaveAs toreportftppath & reportname
WDDoc.Activate

WDDoc.ExportAsFixedFormat OutputFileName:= _
toreportftppath & reportpdf, ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False

ElseIf vb = vbCancel Then
Sheets(sheetname).Select
Exit Sub
End If
End If


WDDoc.Close
WDApp.Quit



Set FSOobj = Nothing

Dim objgetFolder As Object
Dim getfolder As Object
Dim objFile As Object
Dim ID As String
Dim reportID As String

reportID = ActiveSheet.Cells(i, 4).Value
checkTime reportID, ImageFromFTPPath
Set fso = CreateObject("scripting.filesystemobject")
Set objgetFolder = fso.getfolder(ImageFromFTPPath) 'polyclinic FTP drive

count = 0


If Len(reportID) > 9 Then
For Each objFile In objgetFolder.Files 'check each and every file inside
If Left(objFile.Name, Len(reportID)) = reportID Then
If fso.FileExists(Imagetobupath & objFile.Name) = False Then
fso.MoveFile Source:=objFile, Destination:=Imagetobupath
count = count + 1
End If
End If
Next
Else
For Each objFile In objgetFolder.Files 'check each and every file inside