Jean-Guy
Fri Oct 19 09:25:42 PDT 2007
Co was telling us:
Co nous racontait que :
> On 19 okt, 16:40, "Steve Yandl" <syandl_nos...@comcast.net> wrote:
>> The subroutine below assumes that the selected text plus the name of
>> the document (and a space between the two strings) will be appended
>> to a Word document named "C:\Test\myLog.doc" and that myLog.doc is
>> not already open. The clipboard isn't being utilized so there is no
>> need for the forms object library to be available.
>>
>> _____________________________________
>>
>> Sub LotTxtSelection()
>> Dim strTrans As String
>> Dim objDoc As Word.Document
>> strTrans = Selection.Text & " " & ActiveDocument.Name
>> Set objDoc = Documents.Open("C:\Test\myLog.doc")
>> objDoc.Activate
>> With Selection
>> .WholeStory
>> .MoveRight
>> .TypeParagraph
>> .TypeText strTrans
>> End With
>> objDoc.Save
>> objDoc.Close
>> End Sub
>>
>> _____________________________________
>>
<snip>
> Looks great Steve,
>
> But could this also be done with a new document which is already
> opened
> and of which we do not know the name?
>
> Marco
You mean transferring the name of "Document A" and some selected text in
"Document A" into a already opened document?
You need code to determine which other opened document to target. What if
there are more than two opened documents, which one will the code select?
What would be the logic?
By using
ActiveDocument.ActiveWindow.Index
you can get the ActiveDocument window index number.
Then, using some logic you can get the name of the document in another
window.
For example:
'_______________________________________
Dim lngDocIndex As Long
Dim i As Long
lngDocIndex = ActiveDocument.ActiveWindow.Index
For i = 1 To Application.Windows.Count
If i <> lngDocIndex Then
MsgBox Application.Windows(i).Document.Name
Exit For
End If
Next
'_______________________________________
But if you have more than two documents, you need some logic to determine if
you have got the right one.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site:
http://www.word.mvps.org