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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening Word from VB only runs in background

Status
Not open for further replies.

nemosys

Programmer
Oct 10, 2001
5
US
I cannot get Word to become visible when opening it from VB.
I am running on W2K and VB 6.0 sp4. I am also using OfficeXP. I can see Word starting in the task manager when I execute my program. However I cannot kill the task and must reboot to clear Word from the system. If I run my program in debug mode Word does become visible and the app works correctly. Here is a snippet of the code.

Dim oWord As Word.Application
Dim oDoc As Word.Document
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add(filename)
oWord.Visible = True
Set oWord = Nothing
Set oDoc = Nothing

Does anyone have any idea on how to make word become visible?
Thanks.
 
I appreciate your reply.

I tried your code suggestion and I get the same results. Word starts up in the background and cannot be terminated via the task manager. I have to reboot the machine in order to remove Word from running in the background.

If I run the program in debug mode it works correctly.

Any other ideas?

Thanks.
 
Hi, here is a function that i use to automate with Word


Public Function ClientesEnvelopes()
Dim objWord As Word.Document

On Error GoTo HandleErr
DoCmd.Hourglass True
DoCmd.OpenQuery ("qryCONTRATOIMPRIMIRaDEL")

If DIR("C:\Tri\Cartas\Env1.doc") = "" Then
MsgBox "O Ficheiro Word Está Danificado, Não Pode Realizar Esta Operação" _
, vbCritical, "TrialagGES(r)"
DoCmd.Hourglass False
Exit Function
End If


If DIR("c:\Tri\Temp\Temp.mdb") = "" Then
MsgBox "O Ficheiro ACCESS Está Danificado, Não Pode Realizar Esta Operação" _
, vbCritical, "TrialagGES(r)"
DoCmd.Hourglass False
Exit Function
End If

DoCmd.OpenQuery ("qryADICIONAPARACARTASeENV")

Set objWord = GetObject("C:\Tri\Cartas\Env1.doc", "Word.Document")

objWord.MailMerge.MainDocumentType = wdFormLetters
'Torna o Word Visivel
objWord.Application.Visible = True
' Set the mail merge data source as the current database.
objWord.MailMerge.OpenDataSource _
Name:="c:\Tri\Temp\Temp.mdb", _
LinkToSource:=True, _
Connection:="TABLE CONTRATOSIMPTMP"
'Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
Close Main
objWord.Close SaveChanges:=wdDoNotSaveChanges
'objWord.Application.Options.PrintBackground = False
'objWord.Application.ActiveDocument.PrintOut


DoCmd.Hourglass False

Set objWord = Nothing

ExitHere:
Exit Function

' Error handling block added by Error Handler Add-In. DO NOT EDIT this block of code.
' Automatic error handler last updated at 09-23-2001 21:11:27 'ErrorHandler:$$D=09-23-2001 'ErrorHandler:$$T=21:11:27
HandleErr:
Select Case Err.Number
Case Else
DoCmd.Hourglass False
MsgBox "ERRO AO GERAR O FICHEIRO WORD", vbCritical, "TrialagaGES ERROS"
Exit Function
'MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "MenuBarss.ClientesEnvelopes" 'ErrorHandler:$$N=MenuBarss.ClientesEnvelopes
End Select
' End Error handling block.
End Function
Best Regards

---
JoaoTL
NOSPAM_mail@jtl.co.pt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top