Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 运行时错误1004,带“0”;EnvelopeVisible=True";_Vba - Fatal编程技术网

Vba 运行时错误1004,带“0”;EnvelopeVisible=True";

Vba 运行时错误1004,带“0”;EnvelopeVisible=True";,vba,Vba,我有以下代码来激活Excel 2010中的电子邮件窗口。我在另一个宏中有完全相同的代码,它在那里工作得很好。在这两种情况下,宏都由活动工作表上的CommandButton调用。我不明白为什么一个工作簿而不是另一个工作簿会出错。思想? 运行此宏时,会出现以下错误: 运行时错误“1004”: 对象“\u工作簿”的方法“EnvelopeVisible”失败 代码: 我想出来了——似乎必须选择一些东西才能调用信封。就是这样。弄明白了——似乎必须选择一些东西才能调用信封。就这样。我用其他方法解决了这个问题

我有以下代码来激活Excel 2010中的电子邮件窗口。我在另一个宏中有完全相同的代码,它在那里工作得很好。在这两种情况下,宏都由活动工作表上的CommandButton调用。我不明白为什么一个工作簿而不是另一个工作簿会出错。思想? 运行此宏时,会出现以下错误:

运行时错误“1004”: 对象“\u工作簿”的方法“EnvelopeVisible”失败

代码:


我想出来了——似乎必须选择一些东西才能调用信封。就是这样。

弄明白了——似乎必须选择一些东西才能调用信封。就这样。

我用其他方法解决了这个问题

该问题是由于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

我用另一种方法解决了这个问题

该问题是由于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

您是在同一台机器上运行还是在不同的机器上运行?同一台机器。我可以在单独的窗口中打开这两个工作簿并运行宏。一台工作,另一台不工作。你是在同一台机器上运行还是在不同的机器上运行?同一台机器。我可以在单独的窗口中打开这两个工作簿并运行宏。一个有效,另一个无效。