[英]How to use MailMerge field as a condition for deleting a row of table in Word? VBA code needed
[英]How to use a word table as mailmerge datasource
我有一個包含需要用作郵件合並數據源的表格的 Word 文檔。 我已經通過將單詞表的數據復制到 excel 並將工作表用作數據源來實現我的目標。
現在我的問題是:有沒有辦法在不調用 excel 的情況下使用 word table 作為數據源(我的意思是使用 word table 中的數據創建數據源)?
我問這個是因為我需要使用 word-vba 宏,並且我試圖避免打開 excel 實例。
編輯
我將嘗試使用以下偽代碼闡明我正在尋找的內容(我在錯誤的代碼行中添加了“這是什么?”):
Dim mDoc As Document
Dim mTbl As Table
Set mDoc = ActiveDocument
Set mTbl = mDoc.Tables(1)
Dim mDS As MailMerge.DataSource 'What for this?
For C = 1 To mTbl.Columns.Count
'Add Fields
Dim FieldName As String
FieldName = mTbl.Cell(1, C).Range.Text
mDS.Fields.Add (FieldName) 'What for this?
'Add Values
For R = 2 To mTbl.Rows.Count
mDS.Fields(FieldName)(R) = mTbl.Cell(R, C).Range.Text 'What for this?
Next R
Next C
在 Word 中,從一個空白文檔開始,然后添加一個表格。 在頂行輸入類別(即名字、姓氏等)。 然后在下面的行中添加數據。 然后你應該能夠使用這樣的語句來連接:
ActiveDocument.MailMerge.OpenDataSource Name:="Y:\Test\Word\MailmergeSource.docx", LinkToSource:=True, SubType:=wdMergeSubTypeOther
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.