Tag: outlook vba

在Outlook VBA中下标超出范围错误

下面的代码从Excel工作表中获取值并通过Outlook发送邮件。 代码在Outlook VBA中完成:Option Explicit Sub Sendmail() Dim olItem As Outlook.MailItem Dim xlApp As Excel.Application Dim oApp As Outlook.Application Dim xlBook As Excel.Workbook Dim xlSht As Excel.Worksheet Dim WSTbl As Excel.Worksheet Dim sPath As String Dim iRow As Long, I As Long, J As Long, K As Long Dim Signature As String Dim sBody As String, […]

通过Excel VBA发送电子邮件一次一个

我正在使用MS Excel和Outlook 2013.我试图自动化一个Excel电子表格,使用Outlook将5封电子邮件发送到指定的地址。 诀窍是我希望每条消息一次显示一条消息,并且只有在用户点击发送或closures消息时才会转到下一条消息。 这是我到目前为止: Sub Send_Emails() Dim OutApp As Object: Set OutApp = CreateObject("Outlook.Application") Dim OutMail As Object: Set OutMail = OutApp.CreateItem(0) 'Send Email With OutMail .to = "john.doe@mycompany.com" .Subject = "This is the Subject" .Body = "This is message" .Display End With On Error Resume Next: OutMail = Nothing OutApp = Nothing End […]

正确的后期绑定非版本特定的Excel VBA代码

我有一个Excel电子表格,我的VBA代码从共享日历上创buildOutlook约会。 它将由多个项目经理操作(当然不是同一时间)。 我碰到的问题是与多个用户,我发现有一对夫妇正在使用和旧版本的Office,因此我已经了解到,我应该使用“后期绑定”,我想使这与旧版本更兼容。 我似乎无法find任何有关如何将我有迟到绑定的信息,以及我必须创build此代码的所有示例都是早期绑定的。 我可以得到一些关于转换的帮助吗? 我有2个其他模块,我也必须转换,但将是相同的线。 Option Explicit Sub SCHMTG() 'Schedule Meeting Dim wb As Workbook Set wb = ThisWorkbook Dim ws As Worksheet Set ws = wb.Sheets("Projects") ws.Unprotect "" Dim check As Boolean check = False Dim o As Outlook.Application Set o = New Outlook.Application Dim oNS As Outlook.Namespace Set oNS = o.GetNamespace("MAPI") Dim […]

将多个与会者添加到会议邀请

我尝试了以下两种方式来添加多个与会者,但只有最后一个电子邮件地址在.To区域中陈述。 testing1: 失败 .RequiredAttendees = "me@me.com;" .RequiredAttendees = "you@you.com" testing2: 失败 .RequiredAttendees = "me@me.com; you@you.com" 以下是完整的代码: Sub MeetingInvite() Dim rng As Range Dim OutApp As Object Dim OutMail As Object With Application .EnableEvents = False .ScreenUpdating = False End With Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(1) On Error Resume Next With OutMail .RequiredAttendees […]

Excel显示垃圾字符

我在Outlook中编写了一个脚本来导出选定的电子邮件到Excel。 任何人都可以帮助我configurationExcel或我的代码可能需要什么变化,以便它不显示下面的屏幕截图的垃圾邮件? 在一台电脑上显示正确,但没有显示。 以下是我的代码: Const ExcelPath = "c:\outlook\outlook_emails.xlsx" Sub Export_To_Excel() Dim oMail As Outlook.MailItem Set oMail = GetCurrentItem If oMail Is Nothing Then MsgBox "No or Invalid Item selected", vbCritical Exit Sub End If On Error GoTo Err_H ' Get Email Info Email = GetSmtpAddress(oMail) Body = Replace(oMail.Body, Chr(9), vbCrLf) Subject = Replace(oMail.Subject, Chr(9), vbCrLf) […]

使用Outlook VBA从Excel文件复制/粘贴。

好吧,在这里我有一些难题。 这是我正在尝试的罗嗦版本: 在我已经在Outlook中创build的模板中,打开它并拖动一些文件 – 其中之一将是一个Excel文件。 打开Excel文件并读取到预定的最后一个单元格 将最后一行/列的单元格复制到第一个单元格A1 。 将以前在步骤3中复制的单元格粘贴到Outlook正文中 4号是目前我的问题所在。 附上的是代码 Const xlUp = -4162 'Needed to use the .End() method Sub Sample() Dim NewMail As MailItem, oInspector As Inspector Set oInspector = Application.ActiveInspector Dim eAttachment As Object, xlsAttachment As Object, i As Integer, lRow As Integer, lPriorRow As Integer, lCommentRow As Integer '~~> Get […]

SentOnBehalfOf不能在Excel 2010 VBA代码中工作

我正在使用Excel 2010中的Outlook通过VBA脚本工作。一切运行良好,但有一个例外:.SentOnBehalfofName行将不起作用。 这是完整的代码 Sub Mail() ' Working in Office 2010-2013 Dim OutApp As Outlook.Application Dim OutMail As Outlook.MailItem Dim strbody As String ' This is for the Body of the email Dim signature As String ' This is for the email signature On Error Resume Next 'Set OutMail = Nothing 'Set OutApp = Nothing Dim […]

vbaoutlook收件人

来自单元格A1和A2的电子邮件地址都显示在outlook的“to”上。 但“cc”是空的。 如何将单元格A2设置为“cc”? input和输出: 单元格A1是我要“发送给”的电子邮件地址。 单元格A2是我想要“抄送”的电子邮件地址。 VBA代码: Sub Button1_Click() Const olMailItem As Long = 0 Const olTo As Long = 1 Const olCC As Long = 2 Const olBCC As Long = 3 Dim OutApp As Object Dim OutMail As Object Dim myRecipient As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(olMailItem) On Error […]

VBA使用Outlook打开Excel不能打开

嗨,感谢您的帮助。 我在Outlook 2010&2007中有以下代码: Sub Openexcel() Dim xlApp As Object Dim sourceWB As Workbook Dim sourceSH As Worksheet Dim strFile As String Set xlApp = CreateObject("Excel.Application") With xlApp .Visible = True .EnableEvents = False End With strFile = "E:\All documents\susan\work\Excel projects\saving files to directory Clean.xls" Set sourceWB = Workbooks.Open(strFile, , False, , , , , , […]

通过电子邮件在Excel / Outlook中select范围

我有以下代码( Ron de Bruin提供 ),并试图弄清楚如何自定义它以供我自己使用。 当我运行代码时,没有任何反应(因为error handling程序停止错误“下标超出范围”的macros) 但是,当我改变线: ActiveWorkbook.EnvelopeVisible = False 至: ActiveWorkbook.EnvelopeVisible = True 可见的信封允许我做出select并select我要发送给谁等 我想知道为什么它遇到了“超出范围”的错误,并且如果有可能让这个过程自动地通过,而不需要我在事件触发后input事件(这是从Workbook_Open()事件触发的 – 如果这有什么区别,并且在另一个工作表(工作表(“ValLog”))中进行select) 我正在运行的代码是: Private Sub workbook_open() Dim AWorksheet As Worksheet Dim Sendrng, rng As Range Dim answer As Integer On Error GoTo StopMacro answer = MsgBox("Do you want to send e-mail notifications of upcoming tours?", vbYesNo) If answer […]