【问题标题】:VBA macros desn't work in Excel 2016VBA 宏在 Excel 2016 中不起作用
【发布时间】:2017-04-14 23:07:33
【问题描述】:

我使用代码将范围从https://www.rondebruin.nl/win/s1/outlook/bmail2.htm 复制到电子邮件正文中。它在 Excel 2013 中完美运行,但在 Excel 2016 中无法运行。

在 Excel 2016 中,此代码存在错误“运行时错误 '1004':应用程序定义或对象定义错误”:

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

我不知道出了什么问题。我在互联网上找到的所有内容都没有帮助。 有人知道 Excel 2013 和 2016 之间是否存在会影响工作宏的差异?

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    以管理员身份运行 Excel 解决了我的问题。

    从错误描述来看,这对我来说并不明显。

    所以希望它会帮助别人。

    谢谢。

    【讨论】:

      【解决方案2】:

      嘿,我想建议此代码将帮助您将数据范围复制到邮件正文中,它是代码的一部分,需要使用您的代码进行调整,

      ThisWorkbook.PublishObjects.Add( _
          SourceType:=xlSourceRange, _
          Filename:=strFilename, _
          Sheet:=strWorksheetName, _
          Source:=strRangeAddress, _
          HtmlType:=xlHtmlStatic).Publish True
      
      Set objFilesytem = CreateObject("Scripting.FileSystemObject")
      Set objTextstream = objFilesytem.GetFile(strFilename).OpenAsTextStream(1, -2)
      
      strTempText = objTextstream.ReadAll
      objTextstream.Close
      
      For Each objShape In Worksheets(strWorksheetName).Shapes
          If Not Intersect(objShape.TopLeftCell, Worksheets( _
              strWorksheetName).Range(strRangeAddress)) Is Nothing Then
              blnRangeContainsShapes = True
              Exit For
          End If
      Next objShape
      

      【讨论】:

      • 您好,感谢您的回复。但是这段代码是一样的,不幸的是问题仍然存在
      • 不好意思,代码不工作,可能是权限问题,,,!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 2019-04-04
      • 1970-01-01
      • 2018-10-23
      • 2013-08-07
      • 2016-01-23
      • 1970-01-01
      相关资源
      最近更新 更多