Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Paste text to currently open document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sweet_dreams - 31 Aug 2006 21:46 GMT
Hi all,

I have such a problem: I wrote sub to copy text form one doc to
currently open document. I attached this sub to button I would like it
to insert text form another doc in the selection in document which I
edit. But instead of inserting text to currently open doc it copies
text to the file from which this sub takes text:

   Dim OpisKryterium As New Document

   Set OpisKryterium =
Application.Documents.Open(SciezkaKryterium(NrKryt))

   Dim TekstOpisu As Range
   Dim DlugoscTekstu As Long

   DlugoscTekstu = OpisKryterium.Characters.Count

   Set TekstOpisu = OpisKryterium.Range(0, DlugoscTekstu - 1)

   Selection.FormattedText = TekstOpisu.FormattedText

   OpisKryterium.Close
   Set OpisKryterium = Nothing
   Set TekstOpisu = Nothing

I think that it is because of this line:
Selection.FormattedText = TekstOpisu.FormattedText

but I tried to do it with ActiveDocument but result is the same. So how
can I reference to currently open doc.

Please help.

Regards,
sweet_dreams
Jean-Guy Marcil - 31 Aug 2006 23:42 GMT
sweet_dreams was telling us:
sweet_dreams nous racontait que :

> Hi all,
>
[quoted text clipped - 27 lines]
> but I tried to do it with ActiveDocument but result is the same. So
> how can I reference to currently open doc.

Do not use Selection.

What you want is something like this:

'_______________________________________
Dim docSource As Document
Dim docTarget As Document
Dim TekstOpisu As Range
Dim DlugoscTekstu As Long

Set docTarget = ActiveDocument
Set docSource = Application.Documents.Open(SciezkaKryterium(NrKryt))
'What is SciezkaKryterium(NrKryt)?

DlugoscTekstu = docSource.Characters.Count
Set TekstOpisu = docSource.Range(0, DlugoscTekstu - 1)

docTarget.Range.FormattedText = TekstOpisu.FormattedText
'_______________________________________

It is always better to declare Document objects for all the document we
intend to manipulate in our code.
I am not sure if this is what you want... but according to your own code
this will take the full text form a document and insert it (Overwriting any
existing text) in the active document.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

sweet_dreams - 01 Sep 2006 00:23 GMT
Jean-Guy Marcil,

Thanks a lot it is exactly what I wanted to achieve.

Regards,
sweet_dreams

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.