msgbox shows while code executing ?

staticbob

Well-known Member
Joined
Oct 7, 2003
Messages
1,079
Hi,

I have some code that saves the activeworkbook, opens Outlook, creates a new mail item, attaches teh file then sends. Depending on speed of machines and apps running, this can take anything between 1 - 25 seconds.

I have a msgbox asking user to confirm they wish to send, if they click on yes, is there a way of having a msgbox saying "Please Wait" while the code is executing, then a confirmation msg to say completed.

Thanks in Advance, and belated happy new year to all.
Bob
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Cheers Jimboy,

That should work fine, but will it stay on-top while the code is opening Outlook and generating new mail items ?

Also, I have created the userform as described, but am not sure how I can incorporate this into my code . . . . which is below . . .

Cheers

Sub SubMileage()
'Declarations
Dim appOutlook As Object
Dim outMailItem As Object
Dim Created As Boolean
Dim MsgBoxAnswer As Variant

'User Confirmation
MsgBoxAnswer = MsgBox("Are you sure you wish to send the report?", vbYesNo + vbInformation, _
"Email Warning!!!!")
If MsgBoxAnswer <> vbYes Then Exit Sub

'Save document
ActiveWorkbook.SaveAs Filename:="C:\Mileage Return " & Format(Range ("$C$8"), "mmmm-yy")

'Generate mail item
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderOutbox)
Set outMailItem = myOlApp.CreateItem(olMailItem)
outMailItem.Display
If Created Then appOutlook.Quit

'Get info and send mail
Dim CCAddress As String
CCAddress = Application.WorksheetFunction.Substitute(Range("$E$2"), " ", ".") & "@bluestone.plc.uk"
With outMailItem
.CC = CCAddress
.Recipients.Add "la-la@tellietubbies.co.uk"
.Subject = Format(Range("$C$8"), "mmmm-yy") & " Mileage Return for " & Range("$c$5")
.Body = ActiveSheet.Range("$C$6") 'reg number (unique ID)
.Mileage = CStr(ActiveSheet.Range("$G$36")) ' Business Mileage for month
.BillingInformation = CStr(ActiveSheet.Range("$G$41")) 'Private Fuel Recharge
.Categories = CStr(ActiveSheet.Range("$C$8")) 'Month of return
.Attachments.Add ActiveWorkbook.FullName
.Send
End With

Set MailItem = Nothing
If Created Then appOutlook.Quit
Set appOutlook = Nothing

'Check for IP connectivity, inform user accordingly
Dim IPAddress As String
If SocketsInitialize() Then IPAddress = GetIPFromHostName(GetPcName)
If Left(IPAddress, InStr(1, IPAddress, ".") - 1) = "10" Then
MsgBox "Message has been sent to: Bluestone Accounts" & vbNewLine & "and " & Range("$E$2")
Else
MsgBox "You are not connected to the network - The message HAS NOT yet been sent." & vbNewLine & "The message has been generated and saved in your E-mail Outbox." & vbNewLine & "It will be sent when you next connect to the network and open Microsoft Outlook E-Mail."
End If
SocketsCleanup
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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