简体   繁体   English

从 Excel 发送邮件 - 运行时错误“429”:ActiveX 组件无法创建对象

[英]Sending mails from Excel - Run-time error '429': ActiveX component can't create object

I have to rewrite code which works on Win but doesn't on Mac.我必须重写在 Win 上有效但在 Mac 上无效的代码。

When I run the code I got error:当我运行代码时出现错误:

Run-time error '429': ActiveX component can't create object运行时错误“429”:ActiveX 组件无法创建对象

at line: Set iMsg = CreateObject("CDO.Message") .在行: Set iMsg = CreateObject("CDO.Message")

I already Google thru Internet.我已经通过互联网谷歌了。

Dim msgbox1
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim xRange As Range
Dim xCell As Long
Dim xCount As Long
Dim i As Long

' First run the checks that all needed info is there
' before we display the form

If frmEmail.fldSubject.TextLength < 5 Then
    MsgBox "Please fill in a subject for the email", vbExclamation
    Exit Sub
End If

If frmEmail.fldEmailBox.TextLength < 5 Then
    MsgBox "Please put some information in the email body", vbExclamation
    Exit Sub
End If

msgbox1 = MsgBox("Are you sure you want to email all selected users in this Directorate: " & _
vbCrLf & vbCrLf & Worksheets("Contact Info").Cells(12, 4), vbOKCancel + vbExclamation, "Attention! Attention!! Attention!!!")

If msgbox1 = vbOK Then
    msgbox1 = MsgBox("Are you sure you want to email all users using the following SMTP server: " & _
    vbCrLf & vbCrLf & Worksheets("ADMIN").Cells(25, 3), vbOKCancel + vbExclamation, "Attention! Attention!! Attention!!!")

    If msgbox1 = vbOK Then
        Rem msgbox1 = MsgBox("Place holder for email function")
        'Here we go with emailing
        Sheets("Users Details Form").Activate
        Set iMsg = CreateObject("CDO.Message")
        Set iConf = CreateObject("CDO.Configuration")

        iConf.Load -1    ' CDO Source Defaults
        Set Flds = iConf.Fields
        With Flds
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Trim(Worksheets("ADMIN").Range("c24").Value)
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Update
        End With

        Set xRange = Worksheets("Users Details Form").Range("A1:A65536")
        xCount = Application.CountIf(xRange, "x")

        For i = 1 To xCount
            strbody = frmEmail.fldEmailBox.Text
            xCell = xRange.Find("x").Row

            strbody = Replace(strbody, "%%user%%", Range("B" & xCell) & " " & Range("C" & xCell))
            strbody = Replace(strbody, "%%username%%", Range("F" & xCell))
            strbody = Replace(strbody, "%%password%%", Range("G" & xCell))
            strbody = Replace(strbody, "%%role%%", Range("H" & xCell))

            On Error Resume Next
            With iMsg
                Set .Configuration = iConf
                .To = Range("D" & xCell).Value
                .CC = ""
                .BCC = ""
                .From = "" & Worksheets("ADMIN").Range("C22").Value & "<" & Worksheets("ADMIN").Range("C23").Value & ">"
                .Subject = frmEmail.fldSubject.Text
                .TextBody = strbody
                .Send
            End With
            If Err.Number <> 0 Then
                Range("A" & xCell).Value = "F"
                Range("A" & xCell).DisplayFormat.Interior.ColorIndex = iRed
            Else
                If frmEmail.btnNewUserEmail Then
                    Range("A" & xCell).Value = "N"
                    Range("A" & xCell).DisplayFormat.Interior.ColorIndex = Range("A1").DisplayFormat.Interior.ColorIndex
                End If
                If frmEmail.btnExistingUserEmail Then
                    Range("A" & xCell).Value = "E"
                    Range("A" & xCell).DisplayFormat.Interior.ColorIndex = Range("A1").DisplayFormat.Interior.ColorIndex
                End If
                If frmEmail.btnCustom Then
                    Range("A" & xCell).Value = "C"
                    Range("A" & xCell).DisplayFormat.Interior.ColorIndex = Range("A1").DisplayFormat.Interior.ColorIndex
                End If
            End If
            On Error GoTo 0
        Next
    End If
End If
End

Check your references by going to Tools->References in the VBA editor, make sure none are marked as "missing".通过转到 VBA 编辑器中的工具-> 参考来检查您的参考,确保没有标记为“缺失”。

If no references are missing, then typically this is due to a corrupt workbook.如果没有丢失任何引用,那么这通常是由于工作簿损坏造成的。

The solution is to create a new workbook and copy your VBA code into it.解决方案是创建一个新工作簿并将您的 VBA 代码复制到其中。

This means you will need to recreate any worksheets, formatting etc that might be in your corrupted workbook.这意味着您将需要重新创建可能在损坏的工作簿中的任何工作表、格式等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Excel VBA 创建 Word 应用程序:运行时错误“429”:ActiveX 组件无法创建对象 - Creating Word Application using Excel VBA: Run-time error '429': ActiveX component can't create object Excel VBA 编写内嵌 VBScript - 运行时错误“429”:ActiveX 组件无法创建对象 - Excel VBA Writing in-line VBScript - Run-time error '429': ActiveX component can't create object 创建Outlook对象会生成-运行时错误&#39;429&#39;:ActiveX组件无法创建对象 - Creating Outlook object generates - Run-time error '429': ActiveX component can't create object 运行时错误“ 429” activex组件无法创建对象 - run-time error '429' activex component can't create object VBA:Acrobat运行时错误429; ActiveX组件无法创建对象 - VBA: Acrobat Run time error 429; ActiveX component can't create object 使用任务计划程序在 Excel 中运行 selenium v​​ba 宏时,如何修复“运行时错误 429:ActiveX 组件无法创建对象”错误? - How to fix "Run time error 429: ActiveX Component Can't Create Object" Error when using Task Scheduler to run a selenium vba macro in Excel? Excel VBA ActiveX&#39;429&#39;运行时错误 - Excel VBA ActiveX '429' Run-time error ActiveX 组件无法创建 object - 429 - ActiveX component can't create object - 429 脚本在调试模式下工作,但在正常运行下不工作-错误代码:429(ActiveX组件无法创建对象) - Script working in Debug Mode but not in Normal Run - Error Code: 429(ActiveX Component Can't Create Object') 将单元格复制到新工作表列时出现错误429“Activex组件无法创建对象” - Error 429 “Activex component can't create object” when copying Cells to new worksheet Column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM