Dim EmailSent As String
Dim WindowEnd As Date
Dim TimeWindowEnd As Date
Dim MailToBeSent As Range, TotalMailsToBeSent As Range
Dim RouteLoaded As Range, TotalLoadedRoutes As Range
Dim RouteOrdered As Range, TotalOrderedRoutes As Range
Dim RouteName As Range, AllRouteNames As Range
Dim TwEnd As Range, AllTwEnd As Range
Dim RequiredRoute As Boolean
Dim LoadedRoute As Boolean
Dim WindowOver As Boolean
Dim CurrentTime As Date
Dim WindowTime As Date
Sub check()
Set AllRouteNames = ThisWorkbook.Worksheets("Tabelle1").Range("A3:A" & ThisWorkbook.Worksheets("Tabelle1").UsedRange.Rows.Count)
For Each RouteName In AllRouteNames.Cells
Next RouteName
Set AllTwEnd = ThisWorkbook.Worksheets("Tabelle1").Range("D3:D" & ThisWorkbook.Worksheets("Tabelle1").UsedRange.Rows.Count)
For Each TwEnd In AllTwEnd.Cells
CurrentTime = Now()
WindowTime = Format(TwEnd.Value, "HH:MM")
If WindowTime < Format(CurrentTime, "HH:MM") Then
WindowOver = True
MsgBox (WindowTime)
ElseIf WindowTime > Format(CurrentTime, "HH:MM") Then
WindowOver = False
MsgBox (WindowTime)
End If
Next TwEnd
Set TotalOrderedRoutes = ThisWorkbook.Worksheets("Tabelle1").Range("E3:E" & ThisWorkbook.Worksheets("Tabelle1").UsedRange.Rows.Count)
For Each RouteOrdered In TotalOrderedRoutes.Cells
If RouteOrdered = "N" Or RouteOrdered = " " Then
RequiredRoute = False
ElseIf RouteOrdered = "J" Then
RequiredRoute = True
End If
Next RouteOrdered
Set TotalLoadedRoutes = ThisWorkbook.Worksheets("Tabelle1").Range("F3:F" & ThisWorkbook.Worksheets("Tabelle1").UsedRange.Rows.Count)
For Each RouteLoaded In TotalLoadedRoutes.Cells
If RouteLoaded = "N" Then
LoadedRoute = False
ElseIf RouteLoaded = "J" Then
LoadedRoute = True
End If
Next RouteLoaded
Set TotalMailsToBeSent = ThisWorkbook.Worksheets("Tabelle1").Range("G3:G" & ThisWorkbook.Worksheets("Tabelle1").UsedRange.Rows.Count)
For Each MailToBeSent In TotalMailsToBeSent.Cells
If MailToBeSent = "J" Or LoadedRoute = True Then 'Mail was sent (either entered manually at beginning or via script)
MsgBox ("Mail was already sent or route already loaded")
MsgBox ("Required route is " & RequiredRoute)
MailToBeSent.Value = "J"
ElseIf MailToBeSent = " " And RequiredRoute = True And WindowOver = True Then 'Mail wasn't sent, route will load today and time window is over
MsgBox ("MailSent is empty and time window is over, sending e-mail now..")
Call CreateMailAndSend
MailToBeSent.Value = "J"
ElseIf MailToBeSent = " " And RequiredRoute = True And WindowOver = False Then 'Mail wasn't sent, route will load today and time window isn't over
MsgBox ("MailSent is empty but time window is not over yet")
MsgBox ("Required route is " & RequiredRoute)
End If
Next MailToBeSent
End Sub
Моя проблема заключается в том, что этот скрипт успешно проходит по всем столбцам, которые я хочу, но, например, в разделе «bestellt», где J четко показывает , логическое значение будет оцениваться как ложное и, следовательно, не будет делать то, что мне нужно.
Может кто-нибудь увидеть, как я могу улучшить это или что я делаю неправильно? Это первый скрипт, который я написал на VBA и хочу выучить.
Спасибо.