-
Thank you SNB. In fact this is the scenario:
A.docx, B.docx are opened
Merge data on each (.Bookmarks("date").Range.Text = Now)
Browse, select and open another .docx file (C.docx)
This works fine with the code below.
I need to:
Combine A.docx, B.docx in C.docx
Close A.docx, B.docx without saving
Sub Merge_docx()
With ActiveSheet
Dim strFindString As String
Dim intActualRow As Integer
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
For intActualRow = 4 To 6 'rows contain .docx path
strFindString = Sheets("Program").Cells(intActualRow, 7).Value 'strFindString=.docx path
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error Resume Next
Set wdDoc = wdApp.Documents.Open(strFindString)
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
Exit Sub
End If
wdApp.Visible = True
With wdDoc
.Bookmarks("date").Range.Text = Now
End With
Set wdDoc = Nothing
Next
Application.DefaultFilePath = Sheets("User Settings").Cells(103, 2).Value
strFindString = Application.GetOpenFilename("Text Files (*.docx), *.docx") 'let's name it C.docx
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error Resume Next
Set wdDoc = wdApp.Documents.Open(strFindString)
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
Exit Sub
End If
wdApp.Visible = True
'******************WHAT I NEED HERE******************************
'2-Combine A.docx, B.docx in C.docx
'3-Close A.docx, B.docx without saving
End With
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules