Re: need code to copy paste extended

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On 19 okt, 00:32, "Steve Yandl" <syandl_nos...@xxxxxxxxxxx> wrote:
It copies the text that was selected in your document appended with the name
of the active document. You didn't specify a target where you wanted it
pasted so I assumed you would be pressing Ctrl plus v or using some other
method to paste the contents into some other Word document or other
application.

If your intent was to send the text to a different word document or some
text log file, there are better ways to go about it than involving the
Windows clipboard. What is the ultimate goal?

Steve

"Co" <vonclausow...@xxxxxxxxx> wrote in message

news:1192744307.789810.290470@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On 18 okt, 23:07, "Steve Yandl" <syandl_nos...@xxxxxxxxxxx> wrote:
Marco,

You need a reference to the Microsoft Forms object library. Just insert
a
UserForm that won't get used and then go back to a module to create the
subroutine. The sub between the lines should then do what I think you're
asking to do.

______________________________

Sub CopyPlusDocName()
Dim myDataObject As DataObject
Dim strPlus As String
strPlus = Selection.Text & ActiveDocument.Name
Set myDataObject = New DataObject
myDataObject.SetText strPlus
myDataObject.PutInClipboard
End Sub
______________________________

Steve

"Co" <vonclausow...@xxxxxxxxx> wrote in message

news:1192714699.607589.290760@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hi All,

I need some VBA code that will Copy a highlighted part of a document
to the clipboard including
the name of my document (ActiveDocument.Name).

So when I paste it in a new blanc document I will have the highlighted
text and at the end of it my filename, like:

"This is my highlighted text which was copied from another document".
MySourceDoc.20071018.doc

Marco

Steve,

I don't quite understand.
I inserted a UserForm1 and then ran your code but it doesn't Paste
anywhere.

Marco

The goal is to manually select a part of text in my word document.
Then copy that text together with the name of the document into
another (new)
word document, like:

"This is the text that I am going to copy into a new
Document including the name of the source document"
THE.NAME.OF.MY.SOURCE.DOC.20071019.doc

Marco

.



Relevant Pages

  • Re: need code to copy paste extended
    ... Sub CopyPlusDocName() ... Dim myDataObject As DataObject ... Dim strPlus As String ...
    (microsoft.public.word.vba.general)
  • Re: need code to copy paste extended
    ... UserForm that won't get used and then go back to a module to create the ... Dim myDataObject As DataObject ... Dim strPlus As String ...
    (microsoft.public.word.vba.general)
  • Why I received
    ... I am trying to drag an image from an Word document to my program. ... In the dragenter event, I try to check the type of the DataObject in ...
    (microsoft.public.office.developer.automation)