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

Word shows up even if Visible = False 1

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,509
US
I don't know if this is the right forum, or should I post it in forum707

In VB6 (but that's not really relevant) I create some Word documents in the background and don't care to show it to the user. But Word 'flashes' on the screen anyway.

Here is a code sample (early binding of Word) to show what's going on:

Code:
Dim ObjWord As New Word.Application

With ObjWord[green]
    '.Visible = True    'I don't want to see Word[/green]
    .Documents.Add

    With .Selection
        .TypeText Text:="This is a test in Word document"
        .TypeParagraph
    End With

    .ChangeFileOpenDirectory App.Path & "\"
    .ActiveDocument.SaveAs2 FileName:="MyTest04.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15

    [highlight #8AE234].Documents.Close[/highlight][green]
    ''' That's where Word shows up on the screen, so I do:[/green]
    .Visible = False
    .Quit
End With

Set ObjWord = Nothing

Looks like [tt].Documents.Close[/tt] forces Word to show up on the screen :-(
Is there a way to NOT show Word at all [ponder]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
And doesn't it help if you just try to .Quit without .Documents.Close - something like this?

Code:
With ObjWord
    '.Visible = True    'I don't want to see Word
    ...
    ...
[highlight #FCE94F]    '.Documents.Close[/highlight]
    ''' That's where Word shows up on the screen, so I do:
    .Visible = False
    .Quit
End With
 
Thanks mikrom.

Looks like I can just [tt].Quit[/tt] without [tt].Documents.Close[/tt] since I've already Saved this document. And Word stays not Visible [thumbsup2]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top