Open a refernce doc , open another doc and copy contebts to refern

J

justagrunt

Hi,
so far I have the following.
'check whether to create a new word instance or use an existing session
WordRunning = IsWordRunning
If WordRunning Then
Set WordApp = GetObject(, "Word.Application")
Else
Set WordApp = New Word.Application
End If

'open up the reference document
Set WordDoc = WordApp.Documents.Open("C:\Database\25KgPowder\Base.doc") '
With WordApp
.Visible = True
.WindowState = wdWindowStateNormal
End With

'check on the access form which controls are active
'open that section document
'copy it
'and then paste it after the book mark in the reference document

If (Me![Section11]) = True Then
'do something
Set WordDoc =
WordApp.Documents.Open("C:\Database\25KgPowder\Section11.doc")
'copy contents for pasting into original document
'???????????????????

'close the "Section11" document as not required anymore

'?????????????????????????????

'paste this section to the template
'bring original document to focus
'locate the bookmark and paste section11
Set WordDoc = WordApp.Documents.Open("C:\Database\25KgPowder\Base.doc")
Set WordDoc = WordApp.ActiveDocument
Set WordRng = WordDoc.GoTo(what:=wdGoToBookmark, NAME:="frmBookmark")
'paste


Else
'do something
End If

The if statements continue for another 10 conditions.

I am automating from access.
I open an existing document and if the access controls on the form are true,
add sections to the existing document.
How do I copy the second documents contents and add it to the original
document after the bookmark in the original document?
Then I want to close the second documnets session and move on tto add
another section if the next access control is true.
 
R

Rob

You'll want to have different objects so you can switch back and forth. Like
set WordDoc1 to the original document and WordDoc2 to the one you open and
want to copy from. So then you would switch back and forth and essentially do
a Ctrl+A Ctrl+C. So something like this:

Set WordDoc1 = WordApp.Documents.Open("C:\Database\25KgPowder\Base.doc")
Set WordDoc2 = WordApp.Documents.Open("C:\Database\25KgPowder\Section11.doc")

If you do it that way you can open multiple doc2 and switch back to doc1 to
paste whenever you want. Remember to set them to Nothing when you are done.

'switch to the working doc
WordDoc2.Activate
'Copy the whole doc
Selection.WholeStory
Selection.Copy

'close your doc2 and set to nothing if you're done with it
WordDoc2.Close wdDoNotSaveChanges
Set WordDoc2 = Nothing

'switch to Doc1 if it is already open or open it
WordDoc1.Activate

'find the bookmark like you've already done then paste
Selection.PasteAndFormat (<wdRecoveryType>)

For wdRecoveryType open the object browser (F2) and search for it. Pick the
type you want. You'll see things like wdPasteDefault, wdFormatPlainText, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top