Shapes aren't copying over with cells in email macro









up vote
1
down vote

favorite












I have a macro to send out a daily email. It was mostly a copy paste from a website and worked before, however now I have some shapes in the range that I want included in the email. I'm sure there is something glaring that I am missing and I already tried quite a few things to get it to work with no luck.



Here is the first part that seems to be fine.



Sub Send_EOS()

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

Set rng = Nothing
On Error Resume Next

Set rng = Sheets("Wash").Range("B2:H98").SpecialCells(xlCellTypeVisible)

On Error GoTo 0

If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = Sheets("Settings").Range("E31")
.CC = Sheets("Settings").Range("E32")
.BCC = ""
.Subject = "" & Sheets("Shift Plan").Range("V3") & " " & Sheets("Shift Plan").Range("V7") & " Shift Wash"
.HTMLBody = RangetoHTML(rng)
.send
End With
On Error GoTo 0

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing
End Sub


This is where the trouble is. I thought that .DrawingObjects.Delete might be deleting the objects, but removing that didn't fix it. I also thought that the special paste might be doing it and so I changed it to paste all but that didn't work. I also tried no deleting the temp file at the end and not clearing the clipboard to see if something was wrong with the copy, but when I paste it myself the shapes transfer over, but even in the temp file the paste doesn't show the objects. I also tried all of these things together with no luck. I'm a little stuck on this and could use some help. Thanks in advance!



Function RangetoHTML(rng As Range)

Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook

TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With

With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")

TempWB.Close savechanges:=False

Kill TempFile

Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function









share|improve this question





















  • As I'm working through the code, I think it has to have something to do with "Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)" I'm assuming that a TextStream doesn't allow for shapes. So I need to figure out another method of opening the file that allows for shapes and setting "rangetoHTML" to read it.
    – Clayton Lamb
    Nov 10 at 16:35










  • Temporarily remove Kill TempFile, so you can open the published .htm file from a web browser. Does it contain the shapes?
    – Excelosaurus
    Nov 10 at 20:12










  • Tried that and no dice. I think my observation above is wrong. When I run just the chunk of code pasting into the temporary workbook there is still no shapes. But they are there when I use the same type of special paste. Everything also showed up fine when I changed it to rng.CopyPicture. I ended up giving up and just didn't include shapes in the file.
    – Clayton Lamb
    Nov 10 at 22:54














up vote
1
down vote

favorite












I have a macro to send out a daily email. It was mostly a copy paste from a website and worked before, however now I have some shapes in the range that I want included in the email. I'm sure there is something glaring that I am missing and I already tried quite a few things to get it to work with no luck.



Here is the first part that seems to be fine.



Sub Send_EOS()

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

Set rng = Nothing
On Error Resume Next

Set rng = Sheets("Wash").Range("B2:H98").SpecialCells(xlCellTypeVisible)

On Error GoTo 0

If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = Sheets("Settings").Range("E31")
.CC = Sheets("Settings").Range("E32")
.BCC = ""
.Subject = "" & Sheets("Shift Plan").Range("V3") & " " & Sheets("Shift Plan").Range("V7") & " Shift Wash"
.HTMLBody = RangetoHTML(rng)
.send
End With
On Error GoTo 0

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing
End Sub


This is where the trouble is. I thought that .DrawingObjects.Delete might be deleting the objects, but removing that didn't fix it. I also thought that the special paste might be doing it and so I changed it to paste all but that didn't work. I also tried no deleting the temp file at the end and not clearing the clipboard to see if something was wrong with the copy, but when I paste it myself the shapes transfer over, but even in the temp file the paste doesn't show the objects. I also tried all of these things together with no luck. I'm a little stuck on this and could use some help. Thanks in advance!



Function RangetoHTML(rng As Range)

Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook

TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With

With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")

TempWB.Close savechanges:=False

Kill TempFile

Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function









share|improve this question





















  • As I'm working through the code, I think it has to have something to do with "Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)" I'm assuming that a TextStream doesn't allow for shapes. So I need to figure out another method of opening the file that allows for shapes and setting "rangetoHTML" to read it.
    – Clayton Lamb
    Nov 10 at 16:35










  • Temporarily remove Kill TempFile, so you can open the published .htm file from a web browser. Does it contain the shapes?
    – Excelosaurus
    Nov 10 at 20:12










  • Tried that and no dice. I think my observation above is wrong. When I run just the chunk of code pasting into the temporary workbook there is still no shapes. But they are there when I use the same type of special paste. Everything also showed up fine when I changed it to rng.CopyPicture. I ended up giving up and just didn't include shapes in the file.
    – Clayton Lamb
    Nov 10 at 22:54












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a macro to send out a daily email. It was mostly a copy paste from a website and worked before, however now I have some shapes in the range that I want included in the email. I'm sure there is something glaring that I am missing and I already tried quite a few things to get it to work with no luck.



Here is the first part that seems to be fine.



Sub Send_EOS()

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

Set rng = Nothing
On Error Resume Next

Set rng = Sheets("Wash").Range("B2:H98").SpecialCells(xlCellTypeVisible)

On Error GoTo 0

If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = Sheets("Settings").Range("E31")
.CC = Sheets("Settings").Range("E32")
.BCC = ""
.Subject = "" & Sheets("Shift Plan").Range("V3") & " " & Sheets("Shift Plan").Range("V7") & " Shift Wash"
.HTMLBody = RangetoHTML(rng)
.send
End With
On Error GoTo 0

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing
End Sub


This is where the trouble is. I thought that .DrawingObjects.Delete might be deleting the objects, but removing that didn't fix it. I also thought that the special paste might be doing it and so I changed it to paste all but that didn't work. I also tried no deleting the temp file at the end and not clearing the clipboard to see if something was wrong with the copy, but when I paste it myself the shapes transfer over, but even in the temp file the paste doesn't show the objects. I also tried all of these things together with no luck. I'm a little stuck on this and could use some help. Thanks in advance!



Function RangetoHTML(rng As Range)

Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook

TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With

With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")

TempWB.Close savechanges:=False

Kill TempFile

Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function









share|improve this question













I have a macro to send out a daily email. It was mostly a copy paste from a website and worked before, however now I have some shapes in the range that I want included in the email. I'm sure there is something glaring that I am missing and I already tried quite a few things to get it to work with no luck.



Here is the first part that seems to be fine.



Sub Send_EOS()

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

Set rng = Nothing
On Error Resume Next

Set rng = Sheets("Wash").Range("B2:H98").SpecialCells(xlCellTypeVisible)

On Error GoTo 0

If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = Sheets("Settings").Range("E31")
.CC = Sheets("Settings").Range("E32")
.BCC = ""
.Subject = "" & Sheets("Shift Plan").Range("V3") & " " & Sheets("Shift Plan").Range("V7") & " Shift Wash"
.HTMLBody = RangetoHTML(rng)
.send
End With
On Error GoTo 0

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing
End Sub


This is where the trouble is. I thought that .DrawingObjects.Delete might be deleting the objects, but removing that didn't fix it. I also thought that the special paste might be doing it and so I changed it to paste all but that didn't work. I also tried no deleting the temp file at the end and not clearing the clipboard to see if something was wrong with the copy, but when I paste it myself the shapes transfer over, but even in the temp file the paste doesn't show the objects. I also tried all of these things together with no luck. I'm a little stuck on this and could use some help. Thanks in advance!



Function RangetoHTML(rng As Range)

Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook

TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With

With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")

TempWB.Close savechanges:=False

Kill TempFile

Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function






excel vba excel-vba






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 16:00









Clayton Lamb

163




163











  • As I'm working through the code, I think it has to have something to do with "Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)" I'm assuming that a TextStream doesn't allow for shapes. So I need to figure out another method of opening the file that allows for shapes and setting "rangetoHTML" to read it.
    – Clayton Lamb
    Nov 10 at 16:35










  • Temporarily remove Kill TempFile, so you can open the published .htm file from a web browser. Does it contain the shapes?
    – Excelosaurus
    Nov 10 at 20:12










  • Tried that and no dice. I think my observation above is wrong. When I run just the chunk of code pasting into the temporary workbook there is still no shapes. But they are there when I use the same type of special paste. Everything also showed up fine when I changed it to rng.CopyPicture. I ended up giving up and just didn't include shapes in the file.
    – Clayton Lamb
    Nov 10 at 22:54
















  • As I'm working through the code, I think it has to have something to do with "Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)" I'm assuming that a TextStream doesn't allow for shapes. So I need to figure out another method of opening the file that allows for shapes and setting "rangetoHTML" to read it.
    – Clayton Lamb
    Nov 10 at 16:35










  • Temporarily remove Kill TempFile, so you can open the published .htm file from a web browser. Does it contain the shapes?
    – Excelosaurus
    Nov 10 at 20:12










  • Tried that and no dice. I think my observation above is wrong. When I run just the chunk of code pasting into the temporary workbook there is still no shapes. But they are there when I use the same type of special paste. Everything also showed up fine when I changed it to rng.CopyPicture. I ended up giving up and just didn't include shapes in the file.
    – Clayton Lamb
    Nov 10 at 22:54















As I'm working through the code, I think it has to have something to do with "Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)" I'm assuming that a TextStream doesn't allow for shapes. So I need to figure out another method of opening the file that allows for shapes and setting "rangetoHTML" to read it.
– Clayton Lamb
Nov 10 at 16:35




As I'm working through the code, I think it has to have something to do with "Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)" I'm assuming that a TextStream doesn't allow for shapes. So I need to figure out another method of opening the file that allows for shapes and setting "rangetoHTML" to read it.
– Clayton Lamb
Nov 10 at 16:35












Temporarily remove Kill TempFile, so you can open the published .htm file from a web browser. Does it contain the shapes?
– Excelosaurus
Nov 10 at 20:12




Temporarily remove Kill TempFile, so you can open the published .htm file from a web browser. Does it contain the shapes?
– Excelosaurus
Nov 10 at 20:12












Tried that and no dice. I think my observation above is wrong. When I run just the chunk of code pasting into the temporary workbook there is still no shapes. But they are there when I use the same type of special paste. Everything also showed up fine when I changed it to rng.CopyPicture. I ended up giving up and just didn't include shapes in the file.
– Clayton Lamb
Nov 10 at 22:54




Tried that and no dice. I think my observation above is wrong. When I run just the chunk of code pasting into the temporary workbook there is still no shapes. But they are there when I use the same type of special paste. Everything also showed up fine when I changed it to rng.CopyPicture. I ended up giving up and just didn't include shapes in the file.
– Clayton Lamb
Nov 10 at 22:54

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240737%2fshapes-arent-copying-over-with-cells-in-email-macro%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240737%2fshapes-arent-copying-over-with-cells-in-email-macro%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo