1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| Declare Function GetLogicalDriveStrings Lib "kernel32.dll" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public gProjectIdentifier As Double
Public Function ListToArray(s As String, t() As String, séparateur As String) As Integer
Dim iStart As Integer
Dim iEnd As Integer
Dim tMax As Integer
Dim bFin As Integer
Dim buf As String
tMax = 0
ReDim t(tMax)
iStart = 1
Do
iEnd = InStr(iStart, s, séparateur)
If iEnd = 0 Then
iEnd = Len(s) + 1
bFin = True
End If
buf = Mid$(s, iStart, iEnd - iStart)
ReDim Preserve t(tMax)
t(tMax) = buf
tMax = tMax + 1
iStart = iEnd + 1
Loop While Not bFin
ListToArray = tMax
End Function
Public Function RenameFolder(Folder As String) As String
If InStr(Folder, "/") <> 0 Then
Folder = Left(Folder, InStr(Folder, "/") - 1) & Right(Folder, Len(Folder) - InStr(Folder, "/"))
End If
If InStr(Folder, "\") <> 0 Then
Folder = Left(Folder, InStr(Folder, "\") - 1) & Right(Folder, Len(Folder) - InStr(Folder, "\"))
End If
If InStr(Folder, ".") <> 0 Then
Folder = Left(Folder, InStr(Folder, ".") - 1) & Right(Folder, Len(Folder) - InStr(Folder, "."))
End If
RenameFolder = Folder
End Function
Public Function AttachFile(First_Signed As String, fs As Object, TabDir() As String, fichier As String, TFic() As String, Chemin As String, FileName As String, Folder As String, Project As String, Requi_No As String, Rev_No As String) As Integer
Dim retour As Integer
AttachFile = True
' Initialisation des variables
TFic(0) = "*.pdf"
Chemin = CurrentProject.Path
' Appel du choix du fichier
fichier = Trim(TROUVERFICHIER(Chemin, TFic(0)))
Const cSeparatorFolderInPath = "\"
Call ListToArray(Chemin, TabDir, cSeparatorFolderInPath)
For j = 0 To UBound(TabDir) - 1
If j <> 0 Then
ShortChemin = ShortChemin & "\" & TabDir(j)
Else
ShortChemin = TabDir(0)
End If
Next
If InStr(fichier, ":\") > 0 Then
Call ListToArray(fichier, TabDir, cSeparatorFolderInPath)
FileName = Trim(TabDir(UBound(TabDir)))
Else
AttachFile = False
Exit Function
End If
'Copie du fichier depuis C vers le serveur
Set fs = CreateObject("Scripting.FileSystemObject")
a = fs.FolderExists(ShortChemin & "\CERTIFICAT_TEMP\" & Project)
If a = False Then
'create folder
a = fs.CreateFolder(ShortChemin & "\CERTIFICAT_TEMP\" & Project)
End If
Set fs = CreateObject("Scripting.FileSystemObject")
a = fs.FolderExists(ShortChemin & "\CERTIFICAT_TEMP\" & Project & "\" & Folder)
If a = False Then
'create folder
a = fs.CreateFolder(ShortChemin & "\CERTIFICAT_TEMP\" & Project & "\" & Folder)
End If
'File already exists?
a = fs.FileExists(ShortChemin & "\CERTIFICAT_TEMP\" & Project & "\" & Folder & "\" & FileName)
If a = True Then
MsgBox "This File already exist, Please rename it before attach action"
AttachFile = False
Exit Function
End If
If First_Signed = "First" Then
a = fs.CopyFile(fichier, ShortChemin & "\CERTIFICAT_TEMP\" & Project & "\" & Folder & "\" & Folder & "-" & Requi_No & "-" & Rev_No & "-F" & ".pdf")
ElseIf First_Signed = "Signed" Then
a = fs.CopyFile(fichier, ShortChemin & "\CERTIFICAT_TEMP\" & Project & "\" & Folder & "\" & Folder & "-" & Requi_No & "-" & Rev_No & "-S" & ".pdf")
End If
Set fs = Nothing
End Function |
Partager