我有以下代码来激活Excel 2010中的电子邮件窗口。我在另一个宏中具有完全相同的代码,并且它在那里工作正常。在这两种情况下,宏都由活动工作表上的CommandButton调用。我无法弄清楚为什么错误与一个工作簿而不是另一个。想法? 当我运行此宏时,我收到错误:
运行时错误'1004': 对象'_Workbook'的方法'EnvelopeVisible'失败
代码:
Private Sub CommandButton3_Click()
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Item.To = "recipient"
.Item.Subject = "some words"
.Introduction = "some words"
End With
End Sub
答案 0 :(得分:1)
想出来 - 似乎必须选择某些东西才能打电话给信封。就是这样。
答案 1 :(得分:0)
我用其他一些替代方法解决了这个问题。
由于Citrix中的信封对象激活,问题正在发生。 我用谷歌搜索并使用HTML转换功能,我们将Excel范围转换为HTML并将其粘贴到邮件正文中。 通过上述方法,我能够达到目标。
Function RangetoHTML(rng As Range)
' By Ron de Bruin.
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"
'Copy the range and create a new workbook to past the data in
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
'Publish the sheet to a htm file
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
'Read all data from the htm file into RangetoHTML
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=")
'Close TempWB
TempWB.Close savechanges:=False
'Delete the htm file we used in this function
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function