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!

Problem openning and closing word documents

Status
Not open for further replies.

basbrian

Programmer
Feb 18, 2002
49
0
0
AU
I am trying to create a word document from a template. I am getting the word file save as screen when I thought the save as line would do this for me.
Code:
'Start Word and open the document template.
        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add("q:\computer.adm\basbrian\delegation.dot")

        oDoc.SaveAs("q:\computer.adm\basbrian\Delegation for " & CboName.Text & ".doc")
        oDoc.Close()
        oDoc = Nothing
        oDoc = oWord.Documents.Add("q:\computer.adm\basbrian\Delegation for " & CboName.Text & ".doc")
 
That is strange, mine does not do that. The only real difference I can see is I don't use CreateObject. I just Dim oWord as New Word.Application. CreateObject can be hard to close, have you checked your processes to make sure it is ending? If you are having trouble with that part try this sub:

Public Shared Sub ReleaseObject(ByVal o As Object)
Dim i As Integer
If Not o Is Nothing Then
Try
i = System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
While i > 0
i = System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
End While
Catch
Finally
o = Nothing
End Try
End If
End Sub

Use it for both the oWord and the oDoc objects.

HTH...



 
Hi
Close the doc with the false flag:
Code:
oDoc.Close(FALSE)
Or ditch the saveas and save as you close:
Code:
oDoc.Close(TRUE,,"q:\computer.adm\basbrian\Delegation for " & CboName.Text & ".doc")

I'd go for option 1, you just have to type false into the close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top