使用Excel控制重试尝试的批处理传真
我使用CDO向efax.co.uk发送电子邮件传真。我一次向同一传真号码发送多份传真(最多10份)。问题是efax报告我发送的大多数传真都不成功,因为传真号码忙(猜怎么着,忙着发送我的传真)。我使用efax进行了检查,无法配置重试时间,也无法将传真排队到同一号码 因此,我想创建一个单独的Excel实例(可能使用CreateObject(“Excel.application”)),它具有后台批处理宏。第二种情况下,我需要:使用Excel控制重试尝试的批处理传真,excel,vba,fax,createobject,Excel,Vba,Fax,Createobject,我使用CDO向efax.co.uk发送电子邮件传真。我一次向同一传真号码发送多份传真(最多10份)。问题是efax报告我发送的大多数传真都不成功,因为传真号码忙(猜怎么着,忙着发送我的传真)。我使用efax进行了检查,无法配置重试时间,也无法将传真排队到同一号码 因此,我想创建一个单独的Excel实例(可能使用CreateObject(“Excel.application”)),它具有后台批处理宏。第二种情况下,我需要: 有关要发送的传真列表,请参考Excel第一个实例中的工作表 发送电子邮件/
Sub faxTPD()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Variant
vuser = Environ("USERNAME")
vweek = Format(range("ThisWeek"), "yymmdd")
vtenant = range("tblaccounts").ListObject.ListColumns("Name").DataBodyRange(range("statementrow"))
Application.StatusBar = "FAX TPD: " & vtenant
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/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxx@yahoo.co.uk"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxxx"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.yahoo.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
End With
strbody = "Hello Third Party Deduction Team," & vbNewLine & vbNewLine & _
"Please find following Third Party Deduction Application and Rent Schedule for welfare benefit tenant " & vtenant & "." & vbNewLine & vbNewLine & _
"Regards" & vbNewLine & _
"Pritchard Property" & vbNewLine & _
"T: xxxxxxx" & vbNewLine & _
"E: xxxxxxxx@yahoo.co.uk" & vbNewLine & _
"W: http://www.xxxxx"
vpath = "C:\Users\" & vuser & "\Google Drive\WR Tenant Statements\DWP\" & vweek
With iMsg
Set .Configuration = iConf
.To = "441978xxxxxx@efaxsend.com"
.CC = ""
.BCC = ""
.From = """Pritchard Property"" <xxxxxxx@yahoo.co.uk>"
.Subject = "Third Party Deduction Application for Welfare Benefit Tenant " & vtenant
.TextBody = strbody
.addattachment vpath & "\" & vtenant & " DWP TPD.pdf" ' DWP TPD request arrears payment £3.65
.addattachment vpath & "\" & vtenant & " Rent Schedule.pdf" ' Rent Schedule
If range("tblaccounts").ListObject.ListColumns("AST").DataBodyRange(range("statementrow")) <> "" Then
.addattachment range("tblaccounts").ListObject.ListColumns("AST").DataBodyRange(range("statementrow")) ' AST
End If
If range("tblaccounts").ListObject.ListColumns("DWP TPD").DataBodyRange(range("statementrow")) <> "" Then
.addattachment range("tblaccounts").ListObject.ListColumns("DWP TPD").DataBodyRange(range("statementrow")) ' DWP TPD permission
End If
.Send
End With
End Sub
Sub-faxTPD()
作为对象的Dim iMsg
作为对象的Dim-iConf
像弦一样暗的链子
作为变型的Dim FLD
vuser=Environ(“用户名”)
vweek=格式(范围(“本周”),“年月日”)
vtenant=range(“tblaccounts”).ListObject.ListColumns(“Name”).DataBodyRange(range(“statementrow”))
Application.StatusBar=“传真TPD:”&vtenant
设置iMsg=CreateObject(“CDO.Message”)
设置iConf=CreateObject(“CDO.Configuration”)
加载-1'CDO源默认值
设置Flds=iConf.Fields
使用FLD
.项目(”http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.项目(”http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxx@yahoo.co.uk"
.项目(”http://schemas.microsoft.com/cdo/configuration/sendpassword“”=“xxxxxxx”
.项目(”http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.项目(”http://schemas.microsoft.com/cdo/configuration/smtpserver“”=“smtp.mail.yahoo.com”
.项目(”http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.项目(”http://schemas.microsoft.com/cdo/configuration/smtpusessl“”=真
使现代化
以
strbody=“你好,第三方扣除团队,”&vbNewLine&vbNewLine&_
“请查看以下福利福利租户的第三方扣减申请和租金表”&vtenant&“&vnewline&vnewline&_
“问候”&vbNewLine&_
“Pritchard Property”&vbNewLine&_
“T:xxxxxxx”&vbNewLine&_
“E:xxxxxxxx@yahoo.co.uk“&vbNewLine&_
“W:http://www.xxxxx"
vpath=“C:\Users\”&vuser&“\Google Drive\WR-Tenant-Statements\DWP\”&vweek
与iMsg
Set.Configuration=iConf
.To=”441978xxxxxx@efaxsend.com"
.CC=“”
.BCC=“”
.From=“”Pritchard属性“”
.Subject=“福利福利承租人的第三方扣除申请”&vtenant
.TextBody=strbody
.addattachment vpath&“\”&vtenant&“DWP TPD.pdf”'DWP TPD请求欠款支付3.65英镑
.add附件vpath&“\”&vtenant&“Rent Schedule.pdf”'租金表
如果range(“tblaccounts”).ListObject.ListColumns(“AST”).DataBodyRange(range(“statementrow”))“”则
.addattachment范围(“tblaccounts”).ListObject.ListColumns(“AST”).DataBodyRange(范围(“语句行”))的AST
如果结束
如果range(“tblaccounts”).ListObject.ListColumns(“DWP TPD”).DataBodyRange(range(“statementrow”))”),则
.addattachment range(“tblaccounts”).ListObject.ListColumns(“DWP TPD”).DataBodyRange(range(“statementrow”))的DWP TPD权限
如果结束
邮寄
以
端接头
应用程序。OnTime
可能是一种方法。您可以安排一个过程在将来的某个时间运行。同时,Excel工作正常,用户可以继续工作。如果您希望每五分钟发送一次传真,直到发送完所有传真为止,可能是这样的
'Create variables that don't lose scope until the workbook is closed
Public gvaTenants As Variant
Public glTenant As Long
Sub StartFaxes()
'put all the tenants in an 2d array
gvaTenants = Sheet1.ListObjects(1).ListColumns("name").DataBodyRange.Value
'start with the first tentant
glTenant = 1
SendOneFax
End Sub
Sub SendOneFax()
Dim sBody As String
'Send the first fax
' Some CDO setup stuff
sBody = "Dear " & gvaTenants(glTenant, 1) & ":" & vbNewLine & "Rest of message"
' Finish up CDO stuff and send
'increment to the next tenant
glTenant = glTenant + 1
'if we haven't sent the last one, schedule VBA to run this code
'again in five minutes
If glTenant <= UBound(gvaTenants, 1) Then
Application.OnTime Now + TimeSerial(0, 5, 0), "SendOneFax"
End If
'During the five minutes between runs, the user can Excel normally.
'the next time it runs, the user will have to wait a few secs for it to finish
End Sub
“创建在工作簿关闭之前不会失去作用域的变量
作为变体的公共gVatenant
公屋租户只要
子起始轴()
'将所有租户放入2d数组中
gvaTenants=Sheet1.ListObjects(1.ListColumns(“名称”).DataBodyRange.Value
“从第一个帐篷开始
glTenant=1
SendOneFax
端接头
子SendOneFax()
把身体当作绳子
“发第一份传真
“一些CDO设置的东西
sBody=“亲爱的”&gvaTenants(glTenant,1)&“&vbNewLine&“消息的其余部分”
'完成CDO内容并发送
'增加到下一个租户
glTenant=glTenant+1
'如果尚未发送最后一个,请安排VBA运行此代码
“五分钟后再来一次
如果是glTenant,第二个实例有什么帮助?不管你从哪里发邮件,电话线都会占线吗?你不能把它们发送得慢一点吗?是的,我想在excel中按一个按钮,excel会把传真发送得慢一点,比如每次传真间隔5分钟。但是,如果延迟发生在当前实例中,那么这不会冻结用户吗?因此第二实例的需要,第二实例可用于发送传真和发送传真之间的延迟,因此批处理。