This was working but now it isn't... HELP? Now I just get a Run Time Error.

MJ72

Board Regular
Joined
Aug 17, 2021
Messages
64
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I created a button that takes selected table, copies and pastes it into an email between a note & my HTML signature.

Here is the code that was working yesterday but isn't today. ????

Sub Mail_Outlook_With_Signature_Html_1()

Dim outlook As Object
Dim newEmail As Object
Dim xInspect As Object
Dim pageEditor As Object
Dim strbody As String
Set outlook = CreateObject("Outlook.Application")
Set newEmail = outlook.CreateItem(0)

strbody = "Bonjour," & _
"<br><br>SVP, voir ci-dessous pour l'information <br>" & _
"<br><br>Merci! :)<br>" & _
"<br><br>MJ<br>"

With newEmail

.To = ""
.CC = ""
.BCC = ""
.Subject = "Information

Set xInspect = newEmail.GetInspector
Set pageEditor = xInspect.WordEditor
Selection.Copy

pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
pageEditor.Application.Selection.Start = Len(.HTMLBody)
.display

.HTMLBody = strbody & "<br>" & .HTMLBody

End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub


Thoughts?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
In what way does it not work?
Is the outcome different from what was supposed to be the outcome?
Are you getting error messages?
If so, what are they saying?
Please be more specific about your issue, we need more details. Also please use code tags in future posts, see attached image


ScreenShot202.jpg
 
Upvote 0
In what way does it not work?
Is the outcome different from what was supposed to be the outcome?
Are you getting error messages?
If so, what are they saying?
Please be more specific about your issue, we need more details. Also please use code tags in future posts, see attached image


View attachment 45220
I'm getting a Run Time error code #4605 that I was not getting yesterday. The outcome is very different as in it is just presenting the error message rather than opening the email with message, table and signature. I apologise for any lack of clarity. I will remember to use the VBA tag in the future. Thanks GW.
 
Upvote 0
I'm getting a Run Time error code #4605 that I was not getting yesterday. The outcome is very different as in it is just presenting the error message rather than opening the email with message, table and signature. I apologise for any lack of clarity. I will remember to use the VBA tag in the future. Thanks GW.
I just changed the position of ".display" up to underneath "Selection.Copy" and it's now working fine. I'm still very new to VBA and am not sure how that fixed the error but it seems to have done just that. Any explanation that can be provided would be appreciated or a simpler way to achieve the same results from my vba would also be accepted humbly.
 
Upvote 0
Solution
Glad you sorted it and thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

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