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 / July 2005

Tip: Looking for answers? Try searching our database.

Why Word still running?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RB Smissaert - 12 Jul 2005 00:25 GMT
I have the following code to loop through an Excel array and write the
elements to Word documents:

Sub PasteToWord()

   Dim i As Long
   Dim arr
   Dim LR As Long
   Dim strPCT As String

   Dim wd As Word.Application
   'need to add Word here as there also is a DAO Document!
   Dim Doc As Word.Document
   Dim oTextFrame As Word.TextFrame

   LR = Cells(65536, 1).End(xlUp).Row
   arr = Range(Cells(1), Cells(LR, 1))

   Set wd = New Word.Application
   Set Doc = wd.Documents.Open(Left$(Application.Path, 1) &
":\PCT\PCT_Letter.doc")
   Set oTextFrame = Doc.Shapes("txtBox").TextFrame

   For i = 1 To 4
       strPCT = arr(i, 1)
       'Doc.Shapes("txtBox").TextFrame.TextRange.Text = strPCT
       'Doc.Shapes("txtBox").TextFrame.AutoSize = True
       'Doc.Shapes("txtBox").TextFrame.WordWrap = True

       'With oTextFrame
       '.TextRange.Text = strPCT
       '.AutoSize = True
       '.WordWrap = True
       'End With

       oTextFrame.TextRange.Text = strPCT
       oTextFrame.AutoSize = True
       oTextFrame.WordWrap = True

       Doc.SaveAs Left$(Application.Path, 1) & _
                  ":\PCT\" & _
                  Left$(strPCT, InStr(1, strPCT, "PCT", vbBinaryCompare) +
2) & _
                  ".doc"
   Next

   Doc.Close

   'this still leaves a running intance of Word
   '-------------------------------------------
   Set oTextFrame = Nothing
   Set Doc = Nothing
   Set wd = Nothing

End Sub

It works fine, but after running this there still is a running instance of
Word.
I thought I had released all the references to the Word application, so why
is this happening?
Thanks for any advice.

RBS
RB Smissaert - 12 Jul 2005 00:28 GMT
Forget about this, I forgot:

   wd.Quit

RBS

>I have the following code to loop through an Excel array and write the
>elements to Word documents:
[quoted text clipped - 59 lines]
>
> RBS
 
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.