Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WINWORD.EXE not ends in word 2007 when Embedding word document in OLE 1

Status
Not open for further replies.

jambai

Programmer
Mar 21, 2007
58
0
0
US
Hi,

I am using a OLE unbound Control to Embed the word document in the form load, event like this

and When i double clicks (In Place activation), the documents gets activated (A WINWORD.EXE process is opened) and i can edit the document and in the button click event i am saving the document like this :


and I could save the document.

But the WINWORD.EXE process is not closed and keeps running only in Word 2007. So when i run the same form next time, i couldn't access the template file and it says already opened. Please help me...

Thanks
Harish
 
I don't know, and would have to run some tests to confirm one way or the other, but I suspect that the process of instantiating a WordBasic object and then using that to create and save a document leads, somewhere, to creation of a Word Application object which is not terminated, and which can't easily be terminated because you don't have a handle on it.

It would be better not to use WordBasic at all but, for a first try, at least, what about replacing

Code:
Set NewObject = CreateObject("Word.Basic")
NewObject.FileNew
NewObject.EditPaste
NewObject.FileSaveAs DocPath & "\" & NewDoc
NewObject.FileClose
Set NewObject = Nothing

with

Code:
Set NewObject = CreateObject("Word.[red]Application[/red]")
NewObject[red].WordBasic[/red].FileNew
NewObject[red].WordBasic[/red].EditPaste
NewObject[red].WordBasic[/red].FileSaveAs DocPath & "\" & NewDoc
NewObject[red].WordBasic[/red].FileClose
[red]NewObject.Quit[/red]
Set NewObject = Nothing

If that works, then the basic problem is addressed and you can then look at bringing the code into the 21st century. If it fails, I will need to look a bit more closely at it.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Thanks Tony, Appreciate your response.

In my form load, i am loading the ole unbound control like this :

Private Sub Form_Load()
Dim wrdApp As Object
Set wrdApp = CreateObject("Word.Application")

With Me![olePreviewLetter]
.Enabled = True
.Locked = False

' Specify what kind of object can appear in the field.
.OLETypeAllowed = acOLEEmbedded

' Class statement for Word document.
.Class = "Word.Document"

' Specify the file to be embedded.
' Type the correct path name.
.SourceDoc = "C:\mlprog\TempLetter.DOC"

' Create the embedded object.
.Action = acOLECreateEmbed

' Optional size adjustment.
.SizeMode = acOLESizeZoom
End With

wrdApp.Application.Quit
Set wrdApp = Nothing


End Sub


When i double click the ocntrol, it gets activated and opens a Winword.exe process, and i will edit the docuemnt and when i click the File button,

If blnWordAppOpened = True Then

' blnLetterUpdated = True
' On Error Resume Next
Dim NewObject As Object
' Dim wrdApp As Object
' Set wrdApp = CreateObject("Word.Application")

' Dim wrdApp1 As Object
' Set wrdApp1 = GetObject("C:\mlprog\TempLetter.DOC", "Word.Application")

sLetterPath = "C:\mlprog\TempLetter1.DOC"
sLetter = "TempLetter1"

' Copies the embedded object to Clipboard.
' Me!olePreviewLetter.Verb = 0

' Me!olePreviewLetter.Action = 7 ' Activates the application

Me!olePreviewLetter.Object.Application.WordBasic.E ditSelectAll
Me!olePreviewLetter.Object.Application.WordBasic.E ditCopy
Me!olePreviewLetter.Action = 9 'Close the OLE object
Me!olePreviewLetter.Action = 10 ' Delete the OLE Object
DoEvents

'' ' Creates a new document and pastes Clipboard contents.
'' ' Saves the document in the Word directory and closes the
'' ' document.
'' Set NewObject = CreateObject("Word.Basic")
'' NewObject.FileNew
'' NewObject.EditPaste
'' NewObject.FileSaveAs NewDoc
'' NewObject.FileClose
'' NewObject.Appclose
'' NewObject.Application.Quit
''
'' Frees the memory used by the objects.
'' Set NewObject = Nothing


' Open the generated Letter to preserve the formatting and pastes Clipboard contents.
' Saves to a new file and closes the document
Set NewObject = CreateObject("Word.Application")
NewObject.Visible = False

'NewObject.Activate
NewObject.Documents.Open FileName:="C:\mlprog\Template.doc"
NewObject.Selection.WholeStory
NewObject.Selection.Paste

'removes an extra space!
NewObject.Selection.TypeBackspace

' NewObject.ActiveDocument.SaveAs filename:="C:\mlprog\TempLetter1.DOC"
NewObject.ActiveDocument.SaveAs sLetterPath

NewObject.ActiveDocument.Close
NewObject.Application.Quit

' Frees the memory used by the objects.
Set NewObject = Nothing

' wrdApp.Application.Quit
' Set wrdApp = Nothing

' wrdApp1.Application.Quit
' Set wrdApp1 = Nothing

' oWord.Application.Quit
' Set oWord = Nothing
Else
sLetterPath = "C:\mlprog\TempLetter.DOC"
sLetter = "TempLetter"
End If



That WINWORD,EXE is still running and not closes, this happens only in word 2007.

Please guide me how to solve this issue.

Thanks
Harish
 



Check out the GetObject HELP. There's some code there to use any existing instance of the application object, and if none exists, uses CreateObject.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Ya, i tried that, if some other word document is opened, then instead of copying from the ole unbound control, it is copying from the opened document, so it doesnt works for me.

Do you have any other alternate for this???

Thanks
 




You must work with the correct document object. Use faq707-4594 to discover which one or
Code:
dim doc as Word.Document

for each doc in Word.Documents
  debug.print doc.name
next


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Yes, i could find my Word document name in the debug print, so how to close my document. Please guide.

 

Code:
dim doc as Word.Document

for each doc in Word.Documents
  if doc.name = "MYNAME.doc" then doc.close
next
pretty simple.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Yes, i tried this, it worked for me.

THANKS A LOT Skip, Appreciate YOUR HELP, YOU ARE THE MAN.

I have spent lot of time to solve this issue, because this is happening only in word 2007, so couldnt figure out the issue. Thanks for your hlep.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top