copy part of document to new document

B

Ben

Hi,

I would like to know how to automate part of the
documentto be inserted into new document.
pleas advise.

thsnks,
regards,
Ben
 
B

Ben

Hi,

Is there a way that there is a method that will save the
file and the filename.

many tks.

regards,
Ben
 
S

Stefan Blom

Simply add ActiveDocument.Save before the End Sub statement of any of
the macros suggested by Graham Mayor, and you will be prompted to save
the newly created document. For example:

Sub CopySelectedToNewDoc()
Selection.Copy
Documents.Add Template:="Normal", NewTemplate:=False, _
DocumentType:=0
Selection.Paste
ActiveDocument.Save 'Added
End Sub

Does this help?
 
B

ben

Hi,
it works perfectly in office 2000. can it be done in
office 97 as i have encountered error while running in
the office 97. by the way, for the macro part, do we need
to everytime code the vb script for the new file?

regards,
ben
 
S

Stefan Blom

Unfortunately, I haven't been able to test the macro in Word 97.

However, note that the macro assumes the following: (1) that there is
actually something selected when you run it and (2) that the newly
created document has the focus; either of these assumptions could
cause trouble. Below I have tried to take care of these situations by
altering the macro slightly. I have added a test to see if something
is selected before trying to copy and paste. I have also introduced a
variable to reference the newly created document as a Document object:

Sub CopySelectedToNewDoc()
Dim newdoc As Document
Dim s as Selection
Set s = Selection
If s.Type = wdNoSelection Or s.Type = wdSelectionIP Then
MsgBox "Nothing selected. Please try again."
Exit Sub
End If
s.Copy
Set newdoc = Documents.Add()
newdoc.Activate
s.Paste
ActiveDocument.Save
End Sub

Does this make a difference?
 
B

ben

Hi,

It did not help much.
is it possible to determine the number of records in the
original document and copy into separate new documents
(based on number of record) once shot?
Tks

regards,
Ben
 
S

Stefan Blom

Are you talking about a mail merge? If this is the case, you'd
probably get better help if you posted the question in the
microsoft.public.word.mailmerge.fields group instead.
 
B

Ben

Hi,
It is not a mail merge. It is just that a document in
which some part may require to put into new document. can
it be automate?

regards,
Ben
 
S

Stefan Blom

Well, I suggested some macros to copy and paste the current selection
into a new document and prompt you to save them. I might be able to
help further, if you can specify exactly what the problem is with
those macros.
 

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