SJ1991
SJ1991

Reputation: 11

VBA macros desn't work in Excel 2016

I use the code to copy range into email body from https://www.rondebruin.nl/win/s1/outlook/bmail2.htm. It worked perfectly in Excel 2013, but it doesn't work in Excel 2016.

In Excel 2016 there is an error 'Run-time error '1004': Application-defined or object-defined error' for this code:

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

I've no idea what is wrong. All I've found in the Internet didn't help. Does anybody know if there is any difference between Excel 2013 and 2016 that can affect working macros?

Upvotes: 0

Views: 437

Answers (2)

Rajesh Sinha
Rajesh Sinha

Reputation: 197

Hey I would like to suggest this Code will help u to Copy data range into mail body, it's portion of the code,, need to adjust with your code,

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

Upvotes: 0

SJ1991
SJ1991

Reputation: 11

Running the Excel as Administrator solves the problem in my case.

It wasn't obviously for me from the error description.

So hope it'll help someone else.

Thanks.

Upvotes: 1

Related Questions