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

Hide Object Activation

Status
Not open for further replies.

oldSarge98

Programmer
Dec 2, 2015
9
US
Working in Excel 2010 with an embedded Word Document. I want to export(save) the Word Document Object as a .docx file in the file system folder. The following code does the job but when the object is activated it briefly flashes on the screen. I want to avoid that. Here's a sample of the code I've developed:

Code:
Sub SaveEmbeddedFile()
    
    Dim xlsWst                  As Worksheet
    Dim strArchivePath          As String
    Dim objOle                  As OLEObject
    Dim appWord                 As Word.Application
    Dim wrdDoc                  As Word.Document
    
    strArchivePath = Me.Path & "\attachments"
 
    Set xlsWst = ThisWorkbook.Worksheets("attachments")
    Set objOle = xlsWst.OLEObjects("HelpDocument")
    
    objOle.Visible = False [highlight #FCE94F]' does not prevent the flash[/highlight]
[highlight #FCE94F]    ' this is where the word OLE object flashes on the screen[/highlight]
    objOle.Activate

    Set wrdDoc = objOle.Object

    wrdDoc.Application.Visible = False
    wrdDoc.SaveAs2 Filename:=strArchivePath & "\help.docx"
    wrdDoc.Close

    Set wrdDoc = Nothing

[highlight #FCE94F]    ' if the following two lines are omitted we are left with
    ' an instance of WINWORD.EXE in the system processes
    ' but, I'm concerned that doing this will interfere with any
    ' Word instances that the user might have had opened before
    ' having this module executed
[/highlight]    Set appWord = GetObject(Class:="Word.Application")

    appWord.Quit

    Set appWord = Nothing

End Sub 'SaveEmbeddedFile

Any recommendations?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top