I am using a macro to copy a single sheet to a new file, then send that as a Lotus Notes attachment - part of the routine has a message box that comes up asking the user if they want to email the attachment. Sometimes (usually if Notes isn't already open) the msgbox appears, but is hidden behind other open windows. If I click the main Excel title bar (which is flashing - I guess to indicate the msgbox's presence), I see the box and can continue. Is there code that can be inserted to ensure the MsgBox always appears on top???
I'll post my code below (actually it's code I borrowed and pieced together from other board postings) - sorry for it's length. Also, the Session Quit statement doesn't seem to work (won't close out Lotus Notes) - any ideas on that?
I'll post my code below (actually it's code I borrowed and pieced together from other board postings) - sorry for it's length. Also, the Session Quit statement doesn't seem to work (won't close out Lotus Notes) - any ideas on that?
Rich (BB code):
Sub SendNotesMail()
Workbooks.Open Filename:="C:\Temp\Lot Summary Attachment.xls"
Windows("Compactor Import9a.xls").Activate
Sheets("SUMMARY").Select
Cells.Select
Selection.Copy
Windows("Lot Summary Attachment.xls").Activate
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Windows("Compactor Import9a.xls").Activate
Range("A1").Select
Application.CutCopyMode = False
ActiveSheet.Unprotect Password:="password"
ActiveSheet.Shapes("Picture 3").Select
Selection.Copy
Windows("Lot Summary Attachment.xls").Activate
Range("G2").Select
ActiveSheet.Paste
Selection.ShapeRange.IncrementLeft 2.25
Selection.ShapeRange.IncrementTop -14.25
Range("A1").Select
Windows("Compactor Import9a.xls").Activate
Range("A1").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="password"
Windows("Lot Summary Attachment.xls").Activate
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.15)
.BottomMargin = Application.InchesToPoints(0.15)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 97
End With
ActiveWorkbook.Save
Dim Maildb As Object, MailDoc As Object, AttachMe As Object, Session As Object
Dim UserName As String, MailDbName As String
Dim EmbedObj1 As Object
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, _
(Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GetDataBase(vbNullString, MailDbName)
If Not Maildb.IsOpen Then Maildb.OpenMail
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
ans = MsgBox("Would you like to email a copy of this lot's summary sheet?" _
, vbQuestion & vbYesNo, "Send Email")
If ans = vbYes Then
Recipient = InputBox("Please enter the recipient's email address in the following format: john.doe@xxxx.com" _
, "Input email address")
MailDoc.SendTo = Recipient
End If
MailDoc.Subject = "Compactor Lot Summary"
MailDoc.Body = "Look at this lot: " & Range("Sheet1!C4").Value
Set AttachMe = MailDoc.CreateRichTextItem("Attachment")
Set EmbedObj1 = AttachMe.Embedobject(1454, vbNullString, _
"c:\Temp\Lot Summary Attachment.xls", "Attachment")
MailDoc.CreateRichTextItem ("Attachment")
MailDoc.SaveMessageOnSend = True
MailDoc.PostedDate = Now
Call MailDoc.Send(False)
'Session.Quit
Set EmbedObj1 = Nothing: Set AttachMe = Nothing: Set MailDoc = Nothing
Set Maildb = Nothing: Set Session = Nothing
Windows("Lot Summary Attachment.xls").Activate
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Sheets.Add
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub