After realising the all .Select in the above would be causing my code to run slowly, I figured that might be what was causing the problem in the first place!
From my original code, I changed this:
Range("E:J,N:W").Select
Selection.EntireColumn.Hidden = True
Application.Goto Reference:="FilterList2"
Selection.CopyPicture
To:
Range("E:J,N:W").EntireColumn.Hidden = True
wsSheet.Range("FilterList2").CopyPicture
And it worked a treat!
So I now don't need to go through the hassle of unmerging and remerging cells!
My full code is now:
Sub NotifyOffHires()
Application.ScreenUpdating = False
On Error GoTo Errormessage
Dim wsSheet As Worksheet, rRng As Range
Set wsSheet = ActiveSheet
Set rRng = wsSheet.Range("PlantReqTable")
Dim Notes As Object, db As Object, WorkSpace As Object
Dim UIdoc As Object, UserName As String, MailDbName As String
Dim AttachMe As Object, EmbedObj As Object
'Set email addresses
EmailAddress = Range("BuyerEmail").Value
ccEmailAddress = Range("ccBuyer1").Value '& "; " & Range("ccBuyer2").Value
'Set email subject
OffHireSubject = Range("OffHireSubject").Value
'Unprotect sheet
Call PR_UnProtect
'Filter column Y by "O" and copy the selection as a picture
With rRng
.AutoFilter Field:=25, Criteria1:="O"
If .SpecialCells(xlCellTypeVisible).Address = .Rows(1).Address Then
MsgBox "There are no off hire lines set as 'To Order' - Status 'O'."
wsSheet.AutoFilter.ShowAllData
Call PR_Protect
Application.ScreenUpdating = True
Exit Sub
Else
End If
End With
Range("E:J,N:W").EntireColumn.Hidden = True
wsSheet.Range("FilterList2").CopyPicture
'Open Lotus Notes & Get Database
Set Notes = CreateObject("Notes.NotesSession")
UserName = Notes.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, _
(Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set db = Notes.GETDATABASE(vbNullString, MailDbName)
'Create & Open New Document
Set WorkSpace = CreateObject("Notes.NotesUIWorkspace")
Call WorkSpace.COMPOSEDOCUMENT(, , "Memo")
Set UIdoc = WorkSpace.CURRENTDOCUMENT
'Add Picture & text
Call UIdoc.gotofield("Body")
Call UIdoc.FieldSetText("EnterSendTo", EmailAddress)
Call UIdoc.FieldSetText("EnterCopyTo", ccEmailAddress)
Call UIdoc.FieldSetText("Subject", OffHireSubject)
Call UIdoc.INSERTTEXT(WorksheetFunction.Substitute( _
"Hello@@The following off hires have been requested on the plant register:@@", _
"@", vbCrLf))
Call UIdoc.Paste
Call UIdoc.INSERTTEXT(Application.Substitute( _
"@@Thank you@@", "@", vbCrLf))
'Unfilter active sheet
Columns("D:X").Hidden = False
wsSheet.AutoFilter.ShowAllData
'Protect Sheet
Call PR_Protect
Application.ScreenUpdating = True
Exit Sub
'Error handler
Errormessage:
MsgBox "Is Lotus Notes running, and have you put email addresses in the required fields?"
Columns("D:X").Hidden = False
wsSheet.AutoFilter.ShowAllData
Call PR_Protect
Application.ScreenUpdating = True
End Sub
Lesson learned... Avoid .Select unless absolutely necessary!