Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Prevent "XYZ.doc is locked for editing" message

The following code is contained in a UserForm code module and is used to open
a file that stores test results for tests listed in a lab management program
I'm working on. "LinkCell" is a public range variable that contains the path
and name of the file containing the results for a particular test. In other
words, the process is similar to opening a file using a Hyperlink. Two file
types are supported: .xls and .doc.

Opening .xls files works fine. The problem is that if the test results are
stored to a Word document (.doc) instead, the below code doesn't run on first
call. On second call I get the "XYZ.doc is locked for editing. Click 'Notify'
to open a read-only copy ...." message. I want the code to work on first run
and I don't want this message to appear.

There is obviously something happening that I don't understand. It's as if
an instance of the .doc file is opened on the first run but is invisible.
There is no indication that a file is open in the Task bar and if I shrink
the lab management program (.xls) there is no open .doc file hiding beneath.
(I know I'm just being stupid but I'm under the gun to get this finished).

Dim FileExt As String

Private Sub CommandButton1_Click()
OpenFileType LinkCell.Value
End Sub

Private Sub OpenFileType(FileName As String)
Dim i As Long
Dim WordApp As Object, myDoc As Object

i = InStrRev(FileName, ".")
FileExt = Right(FileName, Len(FileName) - i)
Select Case FileExt
Case "xls"
Me.Controls(5).Enabled = True
For i = 1 To 4
Me.Controls(i).Enabled = False
Next
Me.Controls(5).SetFocus
DoEvents
Workbooks.Open FileName
Case "doc"
'This part causes the problem
On Error Resume Next
Set WordApp = CreateObject("Word.Application")
Set myDoc = WordApp.Documents.Open(FileName)
If myDoc Is Nothing Then WordApp.Quit
Set WordApp = Nothing
Set myDoc = Nothing
Unload Me
On Error GoTo 0
End Select
End Sub

Much appreciative of some assistance.

Greg Wilson

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Prevent "XYZ.doc is locked for editing" message

Greg,

Try adding...
WordApp.Visible = True
after...
Set WordApp = CreateObject("Word.Application")

Also, you can check in "Task Manager" to see how instances
of Word are in use...right-click the Taskbar and select Task Manager,
then look at the Processes tab.

Regards,
Jim Cone
San Francisco, USA


"Greg Wilson"
wrote in message

The following code is contained in a UserForm code module and is used to open
a file that stores test results for tests listed in a lab management program
I'm working on. "LinkCell" is a public range variable that contains the path
and name of the file containing the results for a particular test. In other
words, the process is similar to opening a file using a Hyperlink. Two file
types are supported: .xls and .doc.

Opening .xls files works fine. The problem is that if the test results are
stored to a Word document (.doc) instead, the below code doesn't run on first
call. On second call I get the "XYZ.doc is locked for editing. Click 'Notify'
to open a read-only copy ...." message. I want the code to work on first run
and I don't want this message to appear.

There is obviously something happening that I don't understand. It's as if
an instance of the .doc file is opened on the first run but is invisible.
There is no indication that a file is open in the Task bar and if I shrink
the lab management program (.xls) there is no open .doc file hiding beneath.
(I know I'm just being stupid but I'm under the gun to get this finished).

Dim FileExt As String

Private Sub CommandButton1_Click()
OpenFileType LinkCell.Value
End Sub

Private Sub OpenFileType(FileName As String)
Dim i As Long
Dim WordApp As Object, myDoc As Object

i = InStrRev(FileName, ".")
FileExt = Right(FileName, Len(FileName) - i)
Select Case FileExt
Case "xls"
Me.Controls(5).Enabled = True
For i = 1 To 4
Me.Controls(i).Enabled = False
Next
Me.Controls(5).SetFocus
DoEvents
Workbooks.Open FileName
Case "doc"
'This part causes the problem
On Error Resume Next
Set WordApp = CreateObject("Word.Application")
Set myDoc = WordApp.Documents.Open(FileName)
If myDoc Is Nothing Then WordApp.Quit
Set WordApp = Nothing
Set myDoc = Nothing
Unload Me
On Error GoTo 0
End Select
End Sub

Much appreciative of some assistance.

Greg Wilson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Prevent "XYZ.doc is locked for editing" message

Jim, you're awesome - that nailed it !!!

I added WordApp.Activate and I'm in business. I'm suffering from burn out at
the moment and never thought of it. That saved me hours.

Best regards,
Greg Wilson

"Jim Cone" wrote:

Greg,

Try adding...
WordApp.Visible = True
after...
Set WordApp = CreateObject("Word.Application")

Also, you can check in "Task Manager" to see how instances
of Word are in use...right-click the Taskbar and select Task Manager,
then look at the Processes tab.

Regards,
Jim Cone
San Francisco, USA


"Greg Wilson"
wrote in message

The following code is contained in a UserForm code module and is used to open
a file that stores test results for tests listed in a lab management program
I'm working on. "LinkCell" is a public range variable that contains the path
and name of the file containing the results for a particular test. In other
words, the process is similar to opening a file using a Hyperlink. Two file
types are supported: .xls and .doc.

Opening .xls files works fine. The problem is that if the test results are
stored to a Word document (.doc) instead, the below code doesn't run on first
call. On second call I get the "XYZ.doc is locked for editing. Click 'Notify'
to open a read-only copy ...." message. I want the code to work on first run
and I don't want this message to appear.

There is obviously something happening that I don't understand. It's as if
an instance of the .doc file is opened on the first run but is invisible.
There is no indication that a file is open in the Task bar and if I shrink
the lab management program (.xls) there is no open .doc file hiding beneath.
(I know I'm just being stupid but I'm under the gun to get this finished).

Dim FileExt As String

Private Sub CommandButton1_Click()
OpenFileType LinkCell.Value
End Sub

Private Sub OpenFileType(FileName As String)
Dim i As Long
Dim WordApp As Object, myDoc As Object

i = InStrRev(FileName, ".")
FileExt = Right(FileName, Len(FileName) - i)
Select Case FileExt
Case "xls"
Me.Controls(5).Enabled = True
For i = 1 To 4
Me.Controls(i).Enabled = False
Next
Me.Controls(5).SetFocus
DoEvents
Workbooks.Open FileName
Case "doc"
'This part causes the problem
On Error Resume Next
Set WordApp = CreateObject("Word.Application")
Set myDoc = WordApp.Documents.Open(FileName)
If myDoc Is Nothing Then WordApp.Quit
Set WordApp = Nothing
Set myDoc = Nothing
Unload Me
On Error GoTo 0
End Select
End Sub

Much appreciative of some assistance.

Greg Wilson


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Locked for Editing" error on a non-protected file Jim Murray Excel Discussion (Misc queries) 1 March 8th 08 11:42 AM
"Locked for Editing" problem in Excel 2007 Adam Excel Discussion (Misc queries) 1 August 22nd 07 03:29 AM
Getting message: ".xls is locked for editing by ------" Alleysdad101 Excel Discussion (Misc queries) 2 February 7th 07 07:40 PM
How to open a "locked for editing" spreadsheet to unlock it? metmart Excel Discussion (Misc queries) 1 April 26th 06 05:55 PM
Not getting "Locked for Editing" message grinnineddies Excel Discussion (Misc queries) 0 June 17th 05 04:29 PM


All times are GMT +1. The time now is 01:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"