最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

excel - Why does vba keep saying "wdChart" is a variable not defined - Stack Overflow

programmeradmin2浏览0评论

So I just want to basically copy a range of cells in my excel sheet and paste them as a table in my email. This is a way I have seen work for other people and makes sense to me but doesn't seem to work.

Option Explicit

Sub TableEmail()

Dim OutApp As Object, OutMail As Object
Dim wdApp As Object
    

Set wdApp = CreateObject("Word.Application")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

    
    Dim Table As Range
    Dim Subject As String
    Dim Body As String
    Dim SaveName As String
    Dim lastCell As Range
    Dim lastRow As String
    Dim lastLocation As String
    Dim Category As String
    Dim Sunday As String
    Dim Signoff As String
    Dim wordDoc
    
        With ThisWorkbook.Worksheets("Email")
                        
                Set lastCell = .Range("B1").End(xlDown)
                lastRow = lastCell.Row
                lastLocation = .Cells(lastRow, 12).Address
        
            Set Table = .Range("B2", lastLocation)
            
            Table.Copy
        
            Category = .Cells(2, 2).Value
            
            Sunday = .Cells(2, 1).Value
            
            Subject = "Risultati | " & Category & " | " & Sunday
            
            Body = .Cells(3, 14).Value
            
            Signoff = .Cells(8, 14).Value
            
        End With
    
    With OutMail

        .Display
        .To = "[email protected]"
        .Subject = Subject
            
            Set wordDoc = OutMail.GetInspector.WordEditor
                With wordDoc.Range
                    .PasteAndFormat wdChart
                    '.PasteAndFormat Type:=14
                    .insertParagraphAfter
                    .insertParagraphAfter
                    .InsterAfter "A Presto,"
                    .insertParagraphAfter
                    .InsertAfter "Full Name"
                    
                End With
            
        .Body = Body
        
        
    End With

            
    Set OutApp = Nothing
    Set OutMail = Nothing


End Sub

I assumed it was because I am missing a library, but when I used the value instead it still doesn't work. Is there something obvious I'm missing here?

发布评论

评论列表(0)

  1. 暂无评论