|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Copy selected text from one document and paste to new document in same position on the page
I was looking for a long time but unfortunately I cannot get a clear answer anywhere.
What I need is to copy selected text from one word document than open new document and paste the text to new document but in the exactly same position in the page as the original text. Here is what I done so far: Code:
Sub Patient() Dim answer As Integer answer = MsgBox("Please select text to copy", vbQuestion + vbYesNo + vbDefaultButton1, "Info") If answer = vbYes Then ActiveDocument.Bookmarks.Add _ Name:="myplace", Range:=Selection.Range Selection.GoTo What:=wdGoToBookmark, Name:="myplace" With ActiveDocument.Bookmarks .DefaultSorting = wdSortByName .ShowHidden = False End With Selection.Copy Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0 Windows.CompareSideBySideWith "Test_Document.docx" Selection.PasteAndFormat (wdFormatOriginalFormatting) Else MsgBox "Please highlight the text first", 16 End If End Sub What I need is that the selected text will by pasted to exact location on the page as original. The original text selection can be anywhere on the page, depends on what the user selects. I also found that the MS Word can count start and end of my bookmark so I was hoping we can write the VBA to position of pasted text exactly where the original bookmark was: Code:
Sub Count() With ActiveDocument.Bookmarks("myplace") MsgBox .Range.Start & vbTab & .Range.End End With End Sub I have a patient record, where I write basic info about the patient like name, address, telephone number etc., and then I have therapy where I describe all the symptoms and progress what the patient make trough time. I than print the document and store it in cabinet as hard copy, as this is legal requirements. The patient may have many visits, so I keep adding the info to the existing record and each time I need to print it. In order to save paper, I would like to have only the new added text to be printed on the same document I printed already. I always put the existing doc back to printer. I know that the MS Word offers print selection option but when selected text is printed, it is always printed on top of the document and this will print over my existing text. So what I was trying to do is select the required text, assign bookmark, copy bookmark, open new document, paste the text, set the view side by side and then I was manually formatting the text using enter to get it to required location so I can print it on existing paper. Is there any other way to achieve this than VBA? I would be grateful for any advice or help. Many thanks, Peter. |
#2
|
||||
|
||||
Cross-posted at: vba - Copy selected text from one document and paste to new document in same position on the page - Stack Overflow
For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters You're expecting someone to do a lot of coding for you obtain a trivial paper saving. Surely it would be simpler to save the original document so you can keep adding to it. If you're really desperate to save paper, reformat the older content as white text so you can reuse the paper and have only the new content print.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
word macro, word vba " |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Error 4605 while trying to copy and paste with same document | Ilmari | Word VBA | 2 | 05-05-2020 12:08 AM |
Copy contents between parenthesis and paste to end of document | jeffreybrown | Word VBA | 2 | 04-23-2019 07:02 PM |
Font changes when I copy/paste one document into another | RobertWA | Word | 3 | 03-25-2019 06:13 AM |
Why do pages 10-24 disappear when I type in more text on page 2 or paste new text into the document? | RET | Word | 1 | 05-02-2016 07:28 PM |
Is it possible to copy & paste Table of Contents out of one document into another? | mikey386 | Word | 4 | 12-18-2014 08:45 AM |