I would like to have a break where it randomly waits between 5-10 minutes before going to the next i.
Unfortunately the function Application.Wait
does not work in Word.
Do you have another solution for me? I don't know much about macros.
- The Error is: Error during compilation:
Constants, character strings of fixed length, user-defined data fields and Declare statements are not permitted as public elements of object modules.
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Sub Test_DE()
If MsgBox("Wirklich senden?", vbYesNo, "Senden") <> vbYes Then Exit Sub
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument
For i = 1 To .MailMerge.DataSource.RecordCount
With .MailMerge
.Destination = wdSendToEmail
.MailSubject = "xxxx"
.MailFormat = wdMailFormatHTML
.MailAddressFieldName = "EMAIL"
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
End With
.Execute Pause:=False
End With
Delay = Int((600000 - 300000 + 1) * Rnd + 300)
Sleep (Delay)
'CreateObject("Excel.Application").Wait (Now + TimeValue("00:00:Delay"))
'Dim PauseDelay As Long
'PauseDelay = Int((600 - 300 + 1) * Rnd + 300) ' Stores the random interval between 300-480
'Call Pause(PauseDelay) ' Calls Pause with the random interval
Next i
End With
Application.ScreenUpdating = True
End Sub