Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Unable to open Word file from Excel

Here's my code:

Set WordApp = CreateObject("Word.Application")
WordApp.Visible = False
Set WordDoc = WordApp.Documents.Open(myFile)

For some reason I keep getting a runtime error 5457,
which says something like "File is open or being used".
I know for a fact that the Word file is NOT open and nobody is
using yet. I've even tried different Word files, but still the
same result. Does anyone know what the problem might be?
Is it related to the file permissions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Unable to open Word file from Excel

Here's my code:

Set WordApp = CreateObject("Word.Application")
WordApp.Visible = False


Not required since the automated instance will not be visible until you make it
visible and/or give control to the user!

Set WordDoc = WordApp.Documents.Open(myFile)

For some reason I keep getting a runtime error 5457,
which says something like "File is open or being used".
I know for a fact that the Word file is NOT open and nobody is
using yet. I've even tried different Word files, but still the
same result. Does anyone know what the problem might be?
Is it related to the file permissions?


Did you have Word open already, AND opened the file there first? You may have
to close that instance BEFORE using an automated instance to open one of its
files, even though that file was manually closed there.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Unable to open Word file from Excel


Did you have Word open already, AND opened the file there first? You may
have to close that instance BEFORE using an automated instance to open one
of its files, even though that file was manually closed there.


The Word files are closed, closed, closed. I even created new blank Word
files and still the same result. The above code works at home, but
in another network environment I can't get Excel to open any Word file,
even files that I created myself. It gives runtime error 5457.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Unable to open Word file from Excel


Did you have Word open already, AND opened the file there first? You may
have to close that instance BEFORE using an automated instance to open one
of its files, even though that file was manually closed there.


The Word files are closed, closed, closed. I even created new blank Word
files and still the same result. The above code works at home, but
in another network environment I can't get Excel to open any Word file,
even files that I created myself. It gives runtime error 5457.


Hmm! The actual wording of the error Description will give a clue as to why the
file can't be opened. Does the 'other network environment' require permissions,
OR is the file in use by other user[s]?

Note that closing the file in Word does not necessarily release the edit lock
on the file; - it may be necessary to close the using instance as well!

Did you try opening with the ReadOnly arg set to 'True'?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Unable to open Word file from Excel


Hmm! The actual wording of the error Description will give a clue as
to why the file can't be opened. Does the 'other network environment'
require permissions, OR is the file in use by other user[s]?


Nobody is accessing the files in my folder except me. I even
loaded my folder in explorer, left-clicked in my folder, selected
"New-Microsoft Word Document", and named the file as "whatever.docx".
Then I changed my VBA code to open "whatever.docx" and still got the RT
error 5457.


Note that closing the file in Word does not necessarily release the edit
lock on the file; - it may be necessary to close the using instance as
well!

Did you try opening with the ReadOnly arg set to 'True'?


I haven't tried ReadOnly as True yet. I'll try tomorrow and see how it
goes. I assumed it does read only by default, but I hope I'm wrong.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Unable to open Word file from Excel


Hmm! The actual wording of the error Description will give a clue as
to why the file can't be opened. Does the 'other network environment'
require permissions, OR is the file in use by other user[s]?


Nobody is accessing the files in my folder except me. I even
loaded my folder in explorer, left-clicked in my folder, selected
"New-Microsoft Word Document", and named the file as "whatever.docx".
Then I changed my VBA code to open "whatever.docx" and still got the RT
error 5457.


This error has the following description using Err.Raise 5457

Application-defined or object-defined error

What EXACT Err.Description do you get?


Note that closing the file in Word does not necessarily release the edit
lock on the file; - it may be necessary to close the using instance as
well!

Did you try opening with the ReadOnly arg set to 'True'?


I haven't tried ReadOnly as True yet. I'll try tomorrow and see how it
goes. I assumed it does read only by default, but I hope I'm wrong.


This is working for me...


Public Sub OpenWordDoc()
Dim wdApp As Object
Set wdApp = CreateObject("Word.Application")
With wdApp
.Documents.Open ("C:\MyDoc.docx")
.Selection.TypeText ("new text")
.Quit SaveChanges:=True
End With 'wdApp
End Sub

...behind the scenes after creating a blank file via WE.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Unable to open Word file from Excel

On Saturday, October 5, 2019 at 3:00:42 AM UTC-7, GS wrote:

This error has the following description using Err.Raise 5457

Application-defined or object-defined error

What EXACT Err.Description do you get?


I forget the exact description, but a popup box said something along
the lines of "File is in use or open by another application or person",
which is clearly incorrect because I created these random new files in
my own folder that nobody knows about or can see.


This is working for me...


Public Sub OpenWordDoc()
Dim wdApp As Object
Set wdApp = CreateObject("Word.Application")
With wdApp
.Documents.Open ("C:\MyDoc.docx")
.Selection.TypeText ("new text")
.Quit SaveChanges:=True
End With 'wdApp
End Sub

..behind the scenes after creating a blank file via WE.


My first goal is to open the Word file in invisible mode, and then
immediately close the file without editing it, and then close the Word app.
But that just produces RT error 5457. I'll try the ReadOnly flag as True
today and see how it goes.
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Unable to open Word file from Excel

On Saturday, October 5, 2019 at 3:00:42 AM UTC-7, GS wrote:

This error has the following description using Err.Raise 5457

Application-defined or object-defined error

What EXACT Err.Description do you get?


I forget the exact description, but a popup box said something along
the lines of "File is in use or open by another application or person",
which is clearly incorrect because I created these random new files in
my own folder that nobody knows about or can see.


This is working for me...


Public Sub OpenWordDoc()
Dim wdApp As Object
Set wdApp = CreateObject("Word.Application")
With wdApp
.Documents.Open ("C:\MyDoc.docx")
.Selection.TypeText ("new text")
.Quit SaveChanges:=True
End With 'wdApp
End Sub

..behind the scenes after creating a blank file via WE.


My first goal is to open the Word file in invisible mode, and then
immediately close the file without editing it, and then close the Word app.
But that just produces RT error 5457. I'll try the ReadOnly flag as True
today and see how it goes.


The code above does exactly that, plus writes some text!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Unable to open Word file from Excel

On Saturday, October 5, 2019 at 4:27:00 AM UTC-7, GS wrote:

The code above does exactly that, plus writes some text!


I tried your code above, but no luck. I even tried the ReadOnly flag
as True, but no luck. The error that I'm seeing is RT Error 5457 which
says "The file is in use by another application or user.
N:\mydrive\test1.docx)"

Nobody is using or even knows about the file. It exists in my own folder
and I created it myself as a test. I even created blank files names
test2.docx, test3.docx, etc, but received the same message.

The code works fine on my personal laptop, but not on the network
drive at work, which is odd because the file is in my own folder. All
I'm trying to do is copy rich text data into the clipboard, but
I can't even open my own Word file with Excel VBA.
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Unable to open Word file from Excel

On Saturday, October 5, 2019 at 4:27:00 AM UTC-7, GS wrote:

The code above does exactly that, plus writes some text!


I tried your code above, but no luck. I even tried the ReadOnly flag
as True, but no luck. The error that I'm seeing is RT Error 5457 which
says "The file is in use by another application or user.
N:\mydrive\test1.docx)"

Nobody is using or even knows about the file. It exists in my own folder
and I created it myself as a test. I even created blank files names
test2.docx, test3.docx, etc, but received the same message.

The code works fine on my personal laptop, but not on the network
drive at work, which is odd because the file is in my own folder. All
I'm trying to do is copy rich text data into the clipboard, but
I can't even open my own Word file with Excel VBA.


Have you checked via TaskManager to see if there's an automated instance of
Word still running, that may have your file open? **Note that this instance is
not visible in the Taskbar unless you made it visible!**

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Unable to open Word file from Excel


Have you checked via TaskManager to see if there's an automated instance of
Word still running, that may have your file open? **Note that this instance
is not visible in the Taskbar unless you made it visible!**


Nothing is in Task Manager. The Word files are definitely not open.
These files are in my own folder and no other user knows about them
or cares about them. Also, I even restart my computer and run the script
and still get the same message. I have run the script and lots of
different Word files, and still no luck.

I don't know what's going on, because my script runs fine on my
laptop. It only fails on my work network computer.
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Unable to open Word file from Excel


Have you checked via TaskManager to see if there's an automated instance of
Word still running, that may have your file open? **Note that this instance
is not visible in the Taskbar unless you made it visible!**


Nothing is in Task Manager. The Word files are definitely not open.
These files are in my own folder and no other user knows about them
or cares about them. Also, I even restart my computer and run the script
and still get the same message. I have run the script and lots of
different Word files, and still no luck.

I don't know what's going on, because my script runs fine on my
laptop. It only fails on my work network computer.


Perhaps ActiveDirectory or GroupPolicy has disabled scripting for your work
domain's workstations?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Unable to open Word file from Excel

On 05/10/2019 11:48, RG III wrote:
On Saturday, October 5, 2019 at 3:00:42 AM UTC-7, GS wrote:

This error has the following description using Err.Raise 5457

Application-defined or object-defined error

What EXACT Err.Description do you get?


I forget the exact description, but a popup box said something along
the lines of "File is in use or open by another application or person",
which is clearly incorrect because I created these random new files in
my own folder that nobody knows about or can see.


From a administrative cmd prompt, replace {Path} with that of the file

openfiles /query /fo table | find /I "{Path}"

This will give you the process id, which can be found in task manager,
which will lead to the application looking at your file. Probably a
network antivirus program....... :-)

--
Adrian C
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
Unable to open embedded word document from Excel Sylvain Excel Discussion (Misc queries) 0 February 23rd 10 07:44 PM
Suddenly unable to open excel files from Explorer, Word ok Gramps Excel Discussion (Misc queries) 2 January 21st 08 02:46 AM
Unable to open excel file and when view the file size show as 1 KB Kamal Siva Excel Discussion (Misc queries) 1 March 7th 06 03:23 AM
"Unable to read file"message in Word & Excel SPRINTSF Excel Discussion (Misc queries) 2 August 20th 05 01:23 PM
Trying to open Excel/Word files error message "Unable to read file RobM Excel Discussion (Misc queries) 1 February 7th 05 08:11 PM


All times are GMT +1. The time now is 10:35 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"