Copy whole document

J

justagrunt

Hi,
Thanks Perry the API now works.
When I now use the following after the document has opened,

objword.selection.homekey unit:-wdstory
selection.extend
'copy to clipbpoard
selection.copy
'can close document now as copied
set objword=nothing

I am getting the message

Object doesn't support this property or method

Any reason as to the possible cause?

What i'm trying to do is open a document, copy the contents, open a second
document and paste the contents to it.

Thanks
 
J

Jay Freedman

Don't use the Selection, and don't use the clipboard.

Open the source document, create the destination document, and
transfer the contents directly:

Dim srcDoc As Document, destDoc As Document
Set srcDoc = Documents.Open(theFileName)
Set destDoc = Documents.Add
destDoc.Range.FormattedText = srcDoc.Range.FormattedText

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
J

justagrunt

Many Thanks Jay.
--
Regards
Bill


Jay Freedman said:
Don't use the Selection, and don't use the clipboard.

Open the source document, create the destination document, and
transfer the contents directly:

Dim srcDoc As Document, destDoc As Document
Set srcDoc = Documents.Open(theFileName)
Set destDoc = Documents.Add
destDoc.Range.FormattedText = srcDoc.Range.FormattedText

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
J

justagrunt

Hi jay,
back again.
To paste after a bookmark in the destination document, would this be the
correct method?

Set srcDoc=Documents.Open (strcost)
Set destdoc= Documents.add (strfilename)
destdoc.range. Goto What:=wdgotoBookMark , Name= "Section"
destdoc.Range.FormattedText=srcDoc.Range.FormatedText
destdoc.save
srcdoc.close
destdoc.close.

Both dcument paths are found from the explorer API.


--
Best Regards
Bill


Jay Freedman said:
Don't use the Selection, and don't use the clipboard.

Open the source document, create the destination document, and
transfer the contents directly:

Dim srcDoc As Document, destDoc As Document
Set srcDoc = Documents.Open(theFileName)
Set destDoc = Documents.Add
destDoc.Range.FormattedText = srcDoc.Range.FormattedText

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
D

Doug Robbins - Word MVP

strfilename will need to be the name of a template that contains the
bookmark. Or, are you opening an existing document with that name in which
case you would use:

Set destdoc= Documents.Open (strfilename)

The use

With destdoc
.Bookmarks("Section").Range.FormattedText =strfilename
.Close wdSaveChanges
End With
srcdoc.Close wdDoNotSaveChanges

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

justagrunt said:
Hi jay,
back again.
To paste after a bookmark in the destination document, would this be the
correct method?

Set srcDoc=Documents.Open (strcost)
Set destdoc= Documents.add (strfilename)
destdoc.range. Goto What:=wdgotoBookMark , Name= "Section"
destdoc.Range.FormattedText=strfilename
destdoc.save
srcdoc.close
destdoc.close.

Both dcument paths are found from the explorer API.
 

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