Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-11-2020, 04:47 AM
gasparik gasparik is offline Copy selected text from one document and paste to new document in same position on the page Windows 10 Copy selected text from one document and paste to new document in same position on the page Office 2010
Novice
Copy selected text from one document and paste to new document in same position on the page
 
Join Date: May 2020
Posts: 1
gasparik is on a distinguished road
Default 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
So what I done: 1- force the user to select the text to copy, if no selection is made the error message will appears. 2- set the bookmark to name "myplace" 3- copy the bookmark 4- open the new document 4- set the view side by side 5- paste the bookmark text to new document 6- I was manually formatting the text using enter to get it to required location so I can print it on existing paper.

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
Let me describe what I am trying to achieve and why I need this function.

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.
Reply With Quote
  #2  
Old 05-11-2020, 05:41 AM
macropod's Avatar
macropod macropod is offline Copy selected text from one document and paste to new document in same position on the page Windows 7 64bit Copy selected text from one document and paste to new document in same position on the page Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

Tags
word macro, word vba "

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy selected text from one document and paste to new document in same position on the page Error 4605 while trying to copy and paste with same document Ilmari Word VBA 2 05-05-2020 12:08 AM
Copy selected text from one document and paste to new document in same position on the page 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
Copy selected text from one document and paste to new document in same position on the page 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:21 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft