View Single Post
  #6  
Old June 29th, 2004, 10:44 AM
Stefan Blom
external usenet poster
 
Posts: n/a
Default copy part of document to new document

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?

--
Stefan Blom


"ben" wrote in message
...
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
-----Original Message-----
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?

--
Stefan Blom


"Ben" wrote in

message
...
Hi,

Is there a way that there is a method that will save

the
file and the filename.

many tks.

regards,
Ben
-----Original Message-----
See the following article:

http://www.gmayor.com/copying_selected_text.htm

If you want to use the macro solution and need further
help with
installing the macro, also see:

http://www.gmayor.com/installing_macro.htm

--
Stefan Blom


"Ben" wrote in
message
...
Hi,

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

thsnks,
regards,
Ben




.










.