Log in

View Full Version : Weird Problem on One machine with late binding Word Automation



Movian
08-23-2012, 10:17 AM
Hey,
I have a system then uses the following code to open up a word document. This works fine for several hundred computers with all different setups. However i have now one machine (XP - SP3 , Office 2007 SP3)
That has a weird issue, this code generates and error on the .open command UNLESS i set wordapp.visible = true BEFORE that line..... its truly Bizarre! no other machine has a problem like this. Any ideas what may be causing this ? I have the same problem in a similar section that works on bookmarks and i would rather the document remains invisible till that work is done as A its quicker without the screen refreshes and B the user knows its complete when it appears. As always any thoughts and help is appreciated.

Public Function EditReport(Docname As String, subfolder As String)
Dim fso As New FileSystemObject, myrs As New ADODB.Recordset

myrs.Open "SELECT SharedFolderLoc FROM Settings", CurrentProject().Connection, adOpenKeyset, adLockOptimistic

loc = myrs("SharedFolderLoc") & "\Templates\" & subfolder & "\" & Docname
myrs.Close
Set myrs = Nothing

If fso.FileExists(loc & ".doc") Then
Set WordApp = CreateObject("Word.Application")
WordApp.Documents.Open loc & ".doc"
WordApp.ActiveDocument.ActiveWindow.View.Type = 3
WordApp.Visible = True
WordApp.Activate
EditReport = True
Else
MsgBox "Unable to find template " & loc & ".doc please check this file exists, and if needed edit your report lists located in Tools->ReportLists", vbCritical, "Error"
EditReport = False
End If
End Function

Tommy
08-30-2012, 12:28 PM
Try this way instead and see if it works:
If Dir(Loc & ".doc") > "" Then
It may be nothing but timing
I think I would put a DoEvents after the open just to give word time to realize it is working. :)