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
|
Sub displayFreeRooms_Click()
Dim startDate As Date
Dim startHour As Integer
Dim endDate As Date
Dim endHour As Integer
Dim startRow As Integer
Dim endRow As Integer
Dim startCol As String
Dim startVideoCol As String
Dim endCol As String
Dim endVideoCol As String
Dim startMonth As String
Dim endMonth As String
Dim free As Boolean
Dim hasMoreFiles As Boolean
Dim main_file_name As String
Dim main_sheet_name As String
main_file_name = ActiveWorkbook.Name
main_sheet_name = ActiveSheet.Name
'Retrieve the dates from the form filled by the user
startDate = Range("C7").Value
endDate = Range("C11").Value
startHour = Range("C9").Value
endHour = Range("C13").Value
'Transform the dates into rows and columns
startRow = dateToRow(startDate)
endRow = dateToRow(endDate)
startCol = hourToCol(startHour)
startVideoCol = hourToVideoCol(startHour)
endCol = hourToCol(endHour)
endVideoCol = hourToVideoCol(endHour)
hasMoreFiles = True
currentFile = "none"
startMonth = dateToMonth(startDate)
endMonth = dateToMonth(endDate)
If (startMonth = endMonth) Then
'Unprotect the sheet in order to execute the macro
ActiveSheet.Unprotect
'Opens both meeting rooms' files and video rooms' files
openFile = openFiles()
'Clears the previous search if any
nextFreeRow = 8
Clear = clearFreeRooms(main_file_name, main_sheet_name)
Clear = clearFreeVideo(main_file_name, main_sheet_name)
nextFreeRow = 8
'On rend le bouton reserver inclickable
btnReserver.Enabled = False
'Searches free meeting rooms
While (hasMoreFiles = True)
hasMoreFiles = nextFile()
free = isFree(startCol, startRow, endCol, endRow, currentFile, startMonth)
If free = True Then
room = addRoom(main_file_name, main_sheet_name)
'S'il y a une salle libre, on rend le bouton clickable
btnReserver.Enabled = True
End If
Wend
nextFreeRow = 8
' C'est cette partie !!!
'Searches for free video rooms
currentFile = video_room
free = isFreeVideo(startCol, startRow, endCol, endRow, currentFile, startMonth)
If free = True Then
room = addVideoRoom()
End If
'Close both meeting rooms' files and video rooms' files
closeFile = closeFiles()
'Protect the sheet so the users can't modify it
'ActiveSheet.Protect
Else
MsgBox ("Vous devez renseigner deux dates du même mois")
End If
End Sub |
Partager