B
Bill Brotherton
I've been searching for the answer to this on various news
groups. The following method, which opens an RTF file with
the "visible" attribute set to false, will sometimes fail
on the line following Documents.Open. It fails where I try
to then activate the document with Documents.Item
(dataDoc).Activate. The method uses On Error to trap the
error and retry by opening it in a visible manner. This
always succeeds when opening it hidden fails. Like I said
this works fine on several instances of word 2000 and on
others it does not. Some have SR1 and some have no service
patch. Any clues would be much appreciated...
BTW: The parameter p_workDoc is obtained prior to the call
like this: workDoc = ActiveDocument.name
Private Function activateDataDoc(p_workDoc As String)
Dim workPath, dataDoc As String
Dim isVisible As Boolean
dataDoc = makeDataDocPath(p_workDoc)
'NOTE: It looks like using "Visible:=False" does not
always work.
On Error GoTo TryVisible
Documents.Open FileName:="""" + dataDoc + """", _
ConfirmConversions:=False, ReadOnly:=False,
AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="",
Revert:=False, _
WritePasswordDocument:="",
WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, Visible:=False
Documents.Item(dataDoc).Activate
isVisible = False
GoTo done
TryVisible:
On Error GoTo err
Documents.Open FileName:="""" + dataDoc + """", _
ConfirmConversions:=False, ReadOnly:=False,
AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="",
Revert:=False, _
WritePasswordDocument:="",
WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, Visible:=True
Documents.Item(dataDoc).Activate
isVisible = True
GoTo done
err:
MsgBox "Unable to open the associated data file (" +
dataDoc + ").", , constants.productName
done:
If isVisible Then
MsgBox "Word was unable to open the data document
as a hidden file. We will open it as a visible file
instead. This means you will see some unnecessary flashing
when data is retrieved. ", , constants.productName
End If
End Function
groups. The following method, which opens an RTF file with
the "visible" attribute set to false, will sometimes fail
on the line following Documents.Open. It fails where I try
to then activate the document with Documents.Item
(dataDoc).Activate. The method uses On Error to trap the
error and retry by opening it in a visible manner. This
always succeeds when opening it hidden fails. Like I said
this works fine on several instances of word 2000 and on
others it does not. Some have SR1 and some have no service
patch. Any clues would be much appreciated...
BTW: The parameter p_workDoc is obtained prior to the call
like this: workDoc = ActiveDocument.name
Private Function activateDataDoc(p_workDoc As String)
Dim workPath, dataDoc As String
Dim isVisible As Boolean
dataDoc = makeDataDocPath(p_workDoc)
'NOTE: It looks like using "Visible:=False" does not
always work.
On Error GoTo TryVisible
Documents.Open FileName:="""" + dataDoc + """", _
ConfirmConversions:=False, ReadOnly:=False,
AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="",
Revert:=False, _
WritePasswordDocument:="",
WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, Visible:=False
Documents.Item(dataDoc).Activate
isVisible = False
GoTo done
TryVisible:
On Error GoTo err
Documents.Open FileName:="""" + dataDoc + """", _
ConfirmConversions:=False, ReadOnly:=False,
AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="",
Revert:=False, _
WritePasswordDocument:="",
WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto, Visible:=True
Documents.Item(dataDoc).Activate
isVisible = True
GoTo done
err:
MsgBox "Unable to open the associated data file (" +
dataDoc + ").", , constants.productName
done:
If isVisible Then
MsgBox "Word was unable to open the data document
as a hidden file. We will open it as a visible file
instead. This means you will see some unnecessary flashing
when data is retrieved. ", , constants.productName
End If
End Function