Alow delay of 30 secs in Macro after Msgbox

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I have the following macro, which contains a Msgbox. I would like a delay to allow the user to first enter the month and years and once entered then macro to continue


It would be appreciated if someone could amend my code



Code:
 Sub Email_Reports()
With Range("B6")
MsgBox ("Enter the TB extraction  month and year, for e.g. March 2020")

End With

Dim FileArr, i As Long
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFilePicker)
.InitialFileName = "C:\Pull"
If .Show = -1 Then
ReDim FileArr(1 To .SelectedItems.Count)
For i = 1 To .SelectedItems.Count
FileArr(i) = .SelectedItems(i)
Next i
Else
MsgBox "NO FILES SELECTED", vbInformation, ""
Exit Sub
End If
End With
With CreateObject("outlook.application").CreateItem(0)
.Display 
.To = Join(Application.Transpose(Range("E1:E2").Value), ";")
.Subject = "Sales Report for " & Range("b6") & ""


For i = 1 To UBound(FileArr)
.Attachments.Add FileArr(i)
Next i
.HTMLbody = "Hi " & Range("D1") & "<br><br>" & "Attached please find Sales report for " & Range("b6") & "." & "<br><br>" & "Regards" & "<br><br>" & "Howard"

.Display 'Change to Send after testing
End With
Application.ScreenUpdating = True
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Are you talking about placing the code in here
How do you want the month and date entered ?
AND Do you want that date in "D6" ?
VBA Code:
With Range("B6")
MsgBox ("Enter the TB extraction  month and year, for e.g. March 2020")

End With
 
Upvote 0
Hi Michael

I want the date to be inserted in B6 pertaining to code below

Code:
 With Range("B6")
MsgBox ("Enter the TB extraction  month and year, for e.g. March 2020")

End With
 
Upvote 0
So use this at the start of the code, imstead of your with / end with
VBA Code:
Dim ans As Date
MsgBox ("Enter the TB extraction  month and year, for e.g. March 2020")
ans = Application.InputBox("Enter a date", "Date Required", FormatDateTime(Date, vbShortDate), Type:=1)
Range("B6").Value = ans
 
Upvote 0
Thanks for the advise and your code Michael. It works perfectly
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top