View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
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