Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2005

Tip: Looking for answers? Try searching our database.

Hiding Word: Killing the blob!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Howard Kaikow - 17 Apr 2005 17:54 GMT
Code such as the code below executes ugly.

The Documents.Add causes the blob to appear (an empty hidden Word window)
One has to then take action to remove the critter.
Quit causes the blob to briefly appear, then go away.

Makes for an ugly interface.

Is the only way around the issue to lock the desktop with an API?
Or could one just lock the Word window after making it invisible?

   Dim appWord As Word.Application
   Dim docWord As Word.Document

   Set appWord = New Word.Application
   With appWord
       .ScreenUpdating = False
       .Visible = False
       .WindowState = wdWindowStateMinimize

       ' Blob appears
       Set docWord = .Documents.Add(Visible:=False)
       With docWord
           ' Makes blob disappear
           .ActiveWindow.Visible = False
           ' Do stuff here
           .Close
       End With
       ' Blob appears, then goes away
       .Quit
   End With
   Set docWord = Nothing
   Set appWord = Nothing
Signature

http://www.standards.com/; See Howard Kaikow's web site.

Alex Ivanov - 17 Apr 2005 22:51 GMT
Make the appWord.Visible=false right after its creation.

Signature

Please reply to NG only. This email is not monitored.
Alex.

> Code such as the code below executes ugly.
>
[quoted text clipped - 29 lines]
>    Set docWord = Nothing
>    Set appWord = Nothing
Howard Kaikow - 17 Apr 2005 23:16 GMT
> Make the appWord.Visible=false right after its creation.

I'm already doing that.

I posted the following in the winapi newsgroup.
------------------------------------------
When I lock the Word app window with the code below, the lock does not hold
unless I put a breakpoint on, say, the With appWord statement following the
commented out Sleep statement.

Since it worked using a breakpoint, I ASSuMEd that I could use Sleep to
achieve the same effect. Well, I tried Sleep 20000 and that did no good.

What do I have to do to make sure the Lock works?
The code will evetually be part of a .exe or .dll, so cannot rely on manual
breakpoint.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, _
   ByVal lpWindowName As String) As Long
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As
Long) As Long

   Private Declare Function GetWindowText Lib "user32" _
       Alias "GetWindowTextA" _
       (ByVal hWnd As Long, _
        ByVal lpString As String, _
        ByVal cch As Long) As Long

   Private Declare Function GetActiveWindow Lib "user32" () As Long

   Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub btnByeBye_Click()
   Unload Me
End Sub

Private Sub btnNoTemplate_Click()
   Dim appWord As Word.Application
   Dim docWord As Word.Document
   Dim lngHWnd As Long
   Dim lngReturn As Long
   Dim strCaption As String

   Set appWord = New Word.Application
   lngHWnd = FindWindow(vbNullString, "Microsoft Word")
   If lngHWnd = 0 Then
       Debug.Print "Not found"
       appWord.Quit
       Set appWord = Nothing
       Unload Me
       Exit Sub
   Else
       Debug.Print "Handle is" & Str(lngHWnd)
       Debug.Print "Caption is: " & ActiveWindowCaption(lngHWnd)
       lngReturn = LockWindowUpdate(lngHWnd)
       If lngReturn = 0 Then
           Debug.Print "Lock failed"
           appWord.Quit
           Set appWord = Nothing
           Unload Me
           Exit Sub
       Else
           Debug.Print "Lock success:" & Str(lngReturn) & Str(lngHWnd)
       End If
   End If

'    Sleep 1000
   With appWord
       .ScreenUpdating = False
       .Visible = False
       .WindowState = wdWindowStateMinimize

       ' Blob appears
       Set docWord = .Documents.Add(Visible:=False)
       With docWord
           ' Makes blob disappear
           .ActiveWindow.Visible = False
           ' Do stuff here
           .Close
       End With
       ' Blob appears, then goes away
       .Quit
   End With
   Set docWord = Nothing
   Set appWord = Nothing
End Sub

Private Function ActiveWindowCaption(Optional hWnd = -1) As String
   ' Return caption for active window.
   Dim strCaption As String
   Dim lngLen     As Long

   If hWnd = -1 Then
       hWnd = GetActiveWindow()
   End If

   strCaption = String$(255, vbNullChar)
   lngLen = Len(strCaption)

   If (GetWindowText(hWnd, strCaption, lngLen) > 0) Then
       ActiveWindowCaption = strCaption
   Else
       ActiveWindowCaption = ""
   End If
End Function
Alex Ivanov - 18 Apr 2005 02:01 GMT
I have no problem running your code - it runs completely invisible on my PC.
Have you tried to run the same code on another machine? For me it looks like
you might have some corrupted Word registry entries.
You may try to delete the value
HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Word\Data\Settings or
entire Word key (Replace 10.0 with your version of Word and export the key
into a backup file first!) It should be recreated from HKEY_USERS\.Default
hive next time you start the Word. See if you still have the problem after
that.

Signature

Please reply to NG only. This email is not monitored.
Alex.

>> Make the appWord.Visible=false right after its creation.
>
[quoted text clipped - 106 lines]
>    End If
> End Function
Howard Kaikow - 18 Apr 2005 04:30 GMT
I'll try the code with other word versions.
I'm currently using Word 2003.

I've got other code that hides word.
The .exe is at http://www.standards.com/index.html?Sorting.
That .exe was compiled using Word 97. But I just ran from the VB 6 source
using Word 2003 and Word was entirely invisible.

I'll have to check what the problem code does with other word versions.
Signature

http://www.standards.com/; See Howard Kaikow's web site.

> I have no problem running your code - it runs completely invisible on my PC.
> Have you tried to run the same code on another machine? For me it looks like
[quoted text clipped - 116 lines]
> >    End If
> > End Function
Howard Kaikow - 18 Apr 2005 04:41 GMT
> I have no problem running your code - it runs completely invisible on my PC.
> Have you tried to run the same code on another machine?

I forgot to ask.

Did you run the code from VB 6?
If so what SP version?

If not, from which app did you run the code?
Alex Ivanov - 18 Apr 2005 07:08 GMT
I ran it from vb6 ide and from Word macro and it run fine in both cases.
However, when I added some stuff to the body of the with construct, it
chocked on the line .Range.text = "Hello, world!". It looks like a bug in
Word to me. Fortunately, workaround is easy, don't put the "visible"
parameter to documents.add method. Word is already hidden, you don't need it
there. This is my version of the procedure:
Private Sub Form_Load()
  Dim appWord As Word.Application
   Dim docWord As Word.Document

   Set appWord = New Word.Application
   With appWord
       .ScreenUpdating = False
       .Visible = False
       .WindowState = wdWindowStateMinimize

       ' Blob appears
       Set docWord = .Documents.Add '(Visible:=False)
       With docWord
           .Range.Text = "Hello, world!"
           .SaveAs "c:\test.doc"
           ' Makes blob disappear
           '.ActiveWindow.Visible = False
           ' Do stuff here
           .Close wdDoNotSaveChanges
       End With
       ' Blob appears, then goes away
       .Quit
   End With
   Set docWord = Nothing
   Set appWord = Nothing

End Sub

Signature

Please reply to NG only. This email is not monitored.
Alex.

>> I have no problem running your code - it runs completely invisible on my
> PC.
[quoted text clipped - 6 lines]
>
> If not, from which app did you run the code?
Alex Ivanov - 18 Apr 2005 07:25 GMT
I forgot to mention that it's better to use
appWord.Quit wdDoNotSaveChanges
It will ensure that all open docs are closed before quitting with no prompt
to save changes. You won't need to call docWord.Close explicitly in this
case.

Signature

Please reply to NG only. This email is not monitored.
Alex.

>I ran it from vb6 ide and from Word macro and it run fine in both cases.
>However, when I added some stuff to the body of the with construct, it
[quoted text clipped - 40 lines]
>>
>> If not, from which app did you run the code?
Howard Kaikow - 18 Apr 2005 10:56 GMT
> I forgot to mention that it's better to use
>  appWord.Quit wdDoNotSaveChanges
> It will ensure that all open docs are closed before quitting with no prompt
> to save changes. You won't need to call docWord.Close explicitly in this
> case.

I never need to use wdDoNotSaveChanges as I always have my code do what is
needed and using that parameter would hide errors from me, inadvertently
losing changes that should be saved.

In any case, this particual app does not need that because the file has
already been saved prior to the close.
Howard Kaikow - 18 Apr 2005 14:35 GMT
FYI

The same problem occurs automating Word from VB .NET using Word 2003.

So I guess the problem is either with Word or 3rd party apps interfering
with the OLE.

Gotta go to the dentist, I'll try to construct a fresh example after I get
back.

Signature

http://www.standards.com/; See Howard Kaikow's web site.

> I forgot to mention that it's better to use
>  appWord.Quit wdDoNotSaveChanges
[quoted text clipped - 46 lines]
> >>
> >> If not, from which app did you run the code?
Howard Kaikow - 18 Apr 2005 10:38 GMT
I ran into the same problem running from within Word 2003.
I also ran into the same problem using VB 6 and Word 2002.

I then tried VB 6 with Word 97, which forced me to remove the .Visible for
the doc as that is not supported for word 97.

So, I need to try removing .Visible in Word 2003.

Signature

http://www.standards.com/; See Howard Kaikow's web site.

> I ran it from vb6 ide and from Word macro and it run fine in both cases.
> However, when I added some stuff to the body of the with construct, it
[quoted text clipped - 40 lines]
> >
> > If not, from which app did you run the code?
Howard Kaikow - 18 Apr 2005 10:52 GMT
> I ran it from vb6 ide and from Word macro and it run fine in both cases.
> However, when I added some stuff to the body of the with construct, it
> chocked on the line .Range.text = "Hello, world!". It looks like a bug in
> Word to me. Fortunately, workaround is easy, don't put the "visible"
> parameter to documents.add method. Word is already hidden, you don't need it
> there.

I tried eliminating the visibility stuff.
Same problem, unless I insert a break in the code.

The problem could be caused by 3rd party apps such as Norton Auntie Virus
2004 or OmniPage Office Pro or ... interfering with the OLE.

I have other code in which hiding Word does work in Word 2003 does work.
I'll have to try to find out what, if anything, that code does differently.
Perry - 18 Apr 2005 22:48 GMT
I never have problems using Automation if using the GetObject() function
No Word window, no Document window.
A smooth messagebox with no screendisturbances, no sign of Word at all ...

Dim wd As Object
Set wd = GetObject("c:\MyPath\MyDoc.doc")

MsgBox wd.Paragraphs(1).Range

'Do your/any stuff to the doc here,
'not the Window related methods/props

wd.Parent.Quit
Set wd = Nothing

Krgrds,
Perry

> Code such as the code below executes ugly.
>
[quoted text clipped - 31 lines]
> --
> http://www.standards.com/; See Howard Kaikow's web site.
Howard Kaikow - 18 Apr 2005 22:49 GMT
Wow, I Just discovered the problem is being caused by my own Normal.dot.
If I remove the Normal.dot, no more blobs. So either my Normal.dot is the
culprit, or some 3rd party app is not playing nice with my Normal.dot.

First, I'll reconstruct Normal.dot t make sure it is fresh.
If that doesn't do the deed, then I'll have to find out what specifically is
causing the problem.

Sometime last year, I had to change AutoClose to defend against something
being done by OmniPage Office Pro, so that's a likely candidate!
Howard Kaikow - 19 Apr 2005 00:19 GMT
Ayup, that was the problem, except it was AutoExit, not AutoClose.

> Wow, I Just discovered the problem is being caused by my own Normal.dot.
> If I remove the Normal.dot, no more blobs. So either my Normal.dot is the
[quoted text clipped - 6 lines]
> Sometime last year, I had to change AutoClose to defend against something
> being done by OmniPage Office Pro, so that's a likely candidate!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.