PDA

View Full Version : Open document as "Read ONLY" only



Aqua
11-14-2005, 02:46 PM
I am creating an excel spreadsheet that will list form field values from word documents. I am to the point that the basic flow is complete and am working on error handling.

The Error that I would like to correct (not handle) is the case where the document that I am trying to access is already opened. The way the code is written, the infamous " document is in use, open as read only, notify or cancel" message box comes up. I want to automatically select read only. Is this possible? How would I do this?

Thanks in advance, and if this is not clear, let me know and I will try to clarify.
-Dan aka "Aqua"


Private Sub CommandButton1_Click()
Dim fs, d, f, s
Dim strDir As String
' gets filepath
strDir = Application.ActiveWorkbook.Path
x = 2
' creates file system object
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(strDir)
Set fc = f.Files

' opens word application
Set Wdapp = CreateObject("Word.Application")

' opens each word document in filepath
For Each f1 In fc
If Right(f1.Name, 3) = "doc" Then
If Left(f1.Name, 2) <> "~$" Then
Set wddoc = Wdapp.documents.Open(strDir & "\" & f1.shortName)
' gets data from word document and places in excel
With Wdapp.ActiveDocument
Me.Cells(x, 1).Value = .FormFields("Text1").Result
Me.Cells(x, 2).Value = .FormFields("Text2").Result
Me.Cells(x, 3).Value = .FormFields("Text3").Result
Me.Cells(x, 4).Value = .FormFields("Text4").Result
x = x + 1
End With
Set wddoc = Nothing
End If
End If
Next
Set fs = Nothing
Set f = Nothing
Set fc = Nothing
Wdapp.Quit
End Sub

Bob Phillips
11-14-2005, 04:42 PM
I am creating an excel spreadsheet that will list form field values from word documents. I am to the point that the basic flow is complete and am working on error handling.

The Error that I would like to correct (not handle) is the case where the document that I am trying to access is already opened. The way the code is written, the infamous " document is in use, open as read only, notify or cancel" message box comes up. I want to automatically select read only. Is this possible? How would I do this?

Thanks in advance, and if this is not clear, let me know and I will try to clarify.
-Dan aka "Aqua"


Private Sub CommandButton1_Click()
Dim fs, d, f, s
Dim strDir As String
' gets filepath
strDir = Application.ActiveWorkbook.Path
x = 2
' creates file system object
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(strDir)
Set fc = f.Files

' opens word application
Set Wdapp = CreateObject("Word.Application")

' opens each word document in filepath
For Each f1 In fc
If Right(f1.Name, 3) = "doc" Then
If Left(f1.Name, 2) <> "~$" Then
Set wddoc = Wdapp.documents.Open(strDir & "\" & f1.shortName)
' gets data from word document and places in excel
With Wdapp.ActiveDocument
Me.Cells(x, 1).Value = .FormFields("Text1").Result
Me.Cells(x, 2).Value = .FormFields("Text2").Result
Me.Cells(x, 3).Value = .FormFields("Text3").Result
Me.Cells(x, 4).Value = .FormFields("Text4").Result
x = x + 1
End With
Set wddoc = Nothing
End If
End If
Next
Set fs = Nothing
Set f = Nothing
Set fc = Nothing
Wdapp.Quit
End Sub


Always open as read-only?


Set wddoc = Wdapp.documents.Open(strDir & "\" & f1.shortName,readonly:=true)

sheeeng
11-15-2005, 02:41 AM
Always open as read-only?


Set wddoc = Wdapp.documents.Open(strDir & "\" & f1.shortName,readonly:=true)


Same idea I had in mind...:think:

Aqua
11-15-2005, 07:12 PM
Well, I tried this option...and if the file is open, I still get the prompt to choose Read-Only, Notify or cancel. I am trying to surpress this prompt.

A copy of the prompt is attached as well as my test files. IN order to recreate the prompt, just open one of the .docs before executing the code.

Thanks.

Dan

Aqua
12-01-2005, 01:41 PM
Always open as read-only?


Set wddoc = Wdapp.documents.Open(strDir & "\" & f1.shortName,readonly:=true)

XLD - Are you able to assist with this? I really need to find a way to surpress this prompt. Any direction would be appreciated. I posted the following, but since it was not a reply, I figured you may not have noticed the new post.


Well, I tried this option...and if the file is open, I still get the prompt to choose Read-Only, Notify or cancel. I am trying to surpress this prompt.

A copy of the prompt is attached as well as my test files. IN order to recreate the prompt, just open one of the .docs before executing the code.

Thanks.

Dan

geekgirlau
12-01-2005, 02:58 PM
Not tested, but could you try adding

WdApp.DisplayAlerts=wdAlertsNone

prior to opening the file and

WdApp.DisplayAlerts=wdAlertsAll

after the file opens?