2015-11-19 71 views
0

我正在開發vba項目。要求是將多個單詞文檔內容合併成一個單詞文檔。這是由ContentControl標籤完成的。我已經創建了兩個具有唯一內容控制標記ID的word文檔。現在我需要構建將他們的內容合併爲一個邏輯。將來自多個文件的所有內容控制合併爲一個

Set WordDoc = WordApp.Documents.Open(FileName) 

    With WordApp.ActiveDocument 
      For i = 1 To .ContentControls.Count 
       Select Case .ContentControls(i).Tag 
        Case "cc1": strEnding = "st" -- word content including format and style 
        Case "cc2": strEnding = "nd" 
        Case "cc3": strEnding = "rd" 
        Case Else: strEnding = "th" 
       End Select 
      Next 
     End With 

現在我想合併所有數據(包括格式和風格同樣,如果有一個表)到一個單一的文件。

請給我建議我怎麼做到這一點。

+0

出於興趣:爲什麼涉及ms-access? –

回答

0

以一般的方式,它應該使用Range.FormattedText方程的兩邊。在一個文檔中獲取目標Range並將單個內容控件的Range的FormattedText分配給它。

1
Sub Foo() 
Dim i As Long 
Dim MyName As String, MyPath As String 
Application.ScreenUpdating = False 
Documents.Add 

MyPath = "C:\your_path_here\" ' <= change this as necessary 

MyName = Dir$(MyPath & "*.doc") ' not *.* if you just want doc files 

Do While MyName <> "" 
If InStr(MyName, "~") = 0 Then 
Selection.InsertFile _ 
FileName:="""" & MyPath & MyName & """", _ 
ConfirmConversions:=False, Link:=False, _ 
Attachment:=False 
Selection.InsertBreak Type:=wdPageBreak 
End If 

MyName = Dir ' gets the next doc file in the directory 
Loop 

End Sub 
相關問題