自从我安装了2016版的Office后,我有一些VBA宏不起作用。
这是显示不起作用的预键入电子邮件的位。其余代码将按预期运行。
Sub Send_Application()
Application.ScreenUpdating = False
For Each cell In ActiveSheet.Range("NumberOfApps").Cells
If cell.Value = "Y" Then
cell.Offset(0, -1).Value = Worksheets("Data").Range("A2")
cell.Value = "SENT"
cell.Offset(0, 18).Value = "Yes"
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim sTo As String
AppName = "J:\Matrixes\All Sites\Applications\" & Worksheets("Data").Range("E3") & "\" & cell.Offset(0, 13).Value & ".pdf"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = Worksheets("Data").Range("G2") & vbNewLine & vbNewLine & _
"Please find attached our application for payment for the month of " & Worksheets("Data").Range("E2") & "." & vbNewLine & vbNewLine & _
"Can I ask you to check you are happy with this application and I will issue an Vat Invoice to you. If you do have any queries can you please notify me by email before the 15th " & _
Worksheets("Data").Range("E4") & " otherwise we look forward receiving your payment " & Worksheets("Data").Range("E6") & "." & vbNewLine & vbNewLine & _
"Thank You" & vbNewLine & vbNewLine & _
"Kind Regards"
On Error Resume Next
With OutMail
.To = sTo
.CC = ""
.BCC = ""
.Subject = cell.Offset(0, 13).Value
.Body = strbody
.Attachments.Add (AppName)
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Display
End With
'On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End If
Next cell
Application.ScreenUpdating = True
End Sub
我已注释掉“错误恢复时”行,但没有出现错误。
我已经以管理员身份运行Excel和Outlook,并同时启用了所有宏。
如果我使用相同的文本编写一个全新的宏,则在关闭Excel之前,该宏都将起作用。然后我需要再做一次。
我搜索了一个解决方案,但是我尝试的所有方法都无效。