好的,所以我設法讀取表格,但是現在我找不到如何訪問Quickparts來存儲我剛剛讀取的內容。
我的代碼至今看起來像這樣。
Sub ParseTable2QuickParts()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objDoc As Object 'Word.Document
Dim objSel As Object 'Word.Selection
Dim cTitle As String
Dim acRow(10) As String
Dim nRow As Integer
Dim acCol(10) As String
Dim nCol As Integer
Dim acValues(10, 10) As String
On Error Resume Next
Set objOL = Application
If objOL.ActiveInspector.EditorType = olEditorWord Then
Set objDoc = objOL.ActiveInspector.WordEditor
Set objNS = objOL.Session
Set objSel = objDoc.Windows(1).Selection
objSel.Move wdstory, -1
objSel.Move wdTable, 1
objSel.Expand 12
cTitle = Left(objSel.Text, Len(objSel.Text) - 2)
For nCol = 2 To 3
objSel.Move wdRow, 0
objSel.Move wdCell, 1
objSel.Expand 12
acCol(nCol) = Left(objSel.Text, Len(objSel.Text) - 2)
Next
For nRow = 2 To 4
objSel.Move wdRow, 1
objSel.Move wdCell, 0
objSel.Expand 12
acRow(nRow) = Left(objSel.Text, Len(objSel.Text) - 2)
Next
objSel.Move wdstory, -1
objSel.Move wdTable, 1
For nRow = 2 To 4
objSel.Move wdRow, 1
For nCol = 2 To 3
objSel.Move wdCell, 1
objSel.Expand 12
acValues(nCol, nRow) = Left(objSel.Text, Len(objSel.Text) - 2)
Next
Next
objSel.Move wdstory, 1
For nRow = 2 To 4
For nCol = 2 To 3
objSel.InsertAfter cTitle & acCol(nCol) & acRow(nRow) & " => " & acValues(nCol, nRow) & vbCrLf
Next
Next
End If
Set objOL = Nothing
Set objNS = Nothing
End Sub
我只需要替換最後的嵌套循環來存儲我讀過的內容,而不是將它轉儲回消息。任何人都可以將我指向正確的方向嗎?
所以你試圖從你的電子郵件收集數據放在電子表格? – 0m3r
不,我想讀取表格並將其存儲爲Outlook中的快速部分條目。我的難處在於訪問表格和它的單元格。我已閱讀了「第17章:使用項目體」文章,該文章提供了一些線索,但我對Word DOM一無所知,我的所有VBA體驗都是使用Excel。 –