我将自定义表格视图中的Outlook电子邮件导出到Excel。自定义视图中有自定义公式字段。除公式字段外,所有自定义字段都将导出。
这是公式字段:
' AssignedDate'公式字段:IIf([RequestAssigned] = True,Now(),"")
' RequestAssigned'是一个复选框字段,当选中时,AssignedDate字段将捕获检查它的日期和时间。
我收到运行时错误消息 -
运行时错误' -2147024809(8070057)': 无法完成操作。一个或多个参数值无效
如果删除该公式字段,则宏可以正常工作。
Sub InboxToExcel()
Dim objOL As Outlook.Application
Dim objNS As Outlook.Namespace
Dim objInbox As Outlook.Folder
Dim objTable As Outlook.Table
Dim objRow As Outlook.Row
Dim objMsg As Outlook.MailItem
Dim objWB As Excel.Workbook
Dim objWS As Excel.Worksheet
Dim objRange As Excel.Range
Dim strFind As String
Dim strProps As String
Dim arr() As String
Dim val As Variant
Dim i As Integer
Dim intRow As Integer
strProps = _
"SenderName,To,Subject,SentOn,ReadReceiptRequested"
Set objOL = Application
Set objNS = objOL.Session
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objTable = objInbox.GetTable
Set objWB = GetExcelWB()
Set objWS = objWB.Sheets(1)
objWS.Name = "Inbox"
arr = Split(strProps, ",")
intRow = 1
For i = 0 To UBound(arr)
objWS.Cells(intRow, i + 1) = arr(i)
objTable.Columns.Add arr(i)
Next
Set objRange = objWS.Range _
(objWS.Cells(1, 1), objWS.Cells(1, i + 1))
objRange.Font.Bold = True
Do Until objTable.EndOfTable 'POINTING HERE WHILE DEBUGGING
intRow = intRow + 1
Set objRow = objTable.GetNextRow
For i = 0 To UBound(arr)
val = objRow(arr(i))
objWS.Cells(intRow, i + 1) = val
Next
Loop
For i = 1 To (UBound(arr) + 1)
objWS.Columns(i).EntireColumn.AutoFit
Next
objWS.Application.Visible = True
objWS.Activate
Set objOL = Nothing
Set objNS = Nothing
Set objRow = Nothing
Set objWB = Nothing
Set objWS = Nothing
Set objRange = Nothing
End Sub
答案 0 :(得分:0)
您无法直接在公式中检查复选框的值。以下链接显示如何设置代理单元格以存储答案。
http://blog.contextures.com/archives/2013/07/09/use-check-box-result-in-excel-formula/