Excelmacros:运行时错误“1004”一般邮件失败

我们计划尽快将所有用户升级到Outlook 2010和Exchange 2010,但在迁移Outlook时遇到了一些麻烦。 我们有一个Excel电子表格,基本上是一个费用报告,当他们点击电子表格中的一个button时,这个报告会自动通过电子邮件发送给相应的人员。 它使用一些macros(我不是程序员)来实现这一点。 它适用于我们现在拥有的Outlook 2003,但我们的testing用户组无法使用它 – 它们会收到下面的错误。

任何人都可以帮忙解决这个问题 它驱使我坚果!

我试着用Outlook打开并closures它。 在这里输入图像说明

更新:解决

问题是我们的Citrix服务器场设置…由于MS不允许像所有其他办公应用程序那样对Outlook版本进行并排安装,所以我们必须在“testing”xen应用程序服务器上安装Outlook 2010。 由于这些用户是testingOutlook 2010用户,因此他们的configuration文件仅具有将Outlook 2010和Outlook 2010用作其默认电子邮件客户端的权限。 问题出现时,他们将在excel 2003中打开生产xenapp农场的扩展项 – 那里没有安装outlook 2010。 所以它试图通过他们在该服务器上不存在的默认电子邮件客户端(outlook 2010)发送邮件。 而且由于他们的帐户只是configuration为使用Outlook 2010,Excel不知道该怎么做。

我们的解决scheme是在citrix上创build一个新的Excel发布的应用程序,该应用程序安装在与我们的Outlook 2010安装相同的服务器上,将服务器场限制为该testing服务器,并将该应用程序发布给我们的testing用户,同时删除旧的Excel应用程序。 这样,只能在testing服务器上运行Outlook和Excel。

我只能向你展示我必须去的代码,这样我的电子邮件触发了一个Excel电子表格中的button才能工作。 他们改变了一些东西,所以旧的代码不能很好地工作。

Private Sub EmailBlahbutton_Click() Dim mOutlookApp As Object Dim OutMail As Object Dim Intro As String On Error GoTo ErrorHandler Set mOutlookApp = GetObject("", "Outlook.application") Set OutMail = mOutlookApp.CreateItem(0) With Application .EnableEvents = False .ScreenUpdating = False End With 'These are the ranges being emailed. ActiveSheet.Range(blahblahblah).Select 'Intro is the first line of the email Intro = "BLAHBLAHBLHA" 'Set the To and Subject lines. Send the message. With OutMail .To = "[email protected]" .Subject = "More BLAH here" .HTMLBody = Intro & RangetoHTML(Selection) .Send End With With Application .EnableEvents = True .ScreenUpdating = True End With ActiveSheet.Range("A1").Select ActiveWindow.ScrollColumn = ActiveCell.Column ActiveWindow.ScrollRow = ActiveCell.Row Set OutMail = Nothing Set mOutlookApp = Nothing Exit Sub ErrorHandler: Set mOutlookApp = CreateObject("Outlook.application") Resume Next End Sub Function RangetoHTML(rng As Range) ' Changed by Ron de Bruin 28-Oct-2006 ' Working in Office 2000-2010 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