|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
open word doc without read only error
hi
i have the following code Code:
Dim wdApp As Object
Set wdApp = CreateObject("Word.Application")
wdApp.DisplayAlerts = wdAlertsNone
FileName = "C:\Log.txt"
SetAttr FileName, vbReadOnly
wdApp.Documents.Open FileName, ConfirmConversions:=False, ReadOnly:=True
wdApp.Visible = True
i still can't open the document without an error message remimding me i can only open the document in read only . . anyone else had a similar problem ?? |
|
#2
|
|||
|
|||
|
actually now i am able to open the word pad document but after i close it and return to my program i'll trigger an event which is logged and then the program crashes with -
run time error '75', Path/File Access Error the same log i am opening is that which is written to when an event is logged. is there a way i can get round this access problem ? |
|
#3
|
|||
|
|||
|
Maybe make a copy of the active log file and use the copy with your code? If you're only reading the log and not writing to it that should prevent interference from other processes.
|
|
#4
|
|||
|
|||
|
yup, one filecopy statement and it all works okay
thanks and happy xmas . . |
|
#5
|
|||
|
|||
|
actually i have just realisied this only works once. After it has copied the file once any other attmpts to copy result in a path or access error. I have tried to kill the copy file so it can make a new copy each time as required but this also results in an access error.
is there a way i can override all the file protection and just kill the copy ? i cant beleive its so ardous just to open a text file as read only . . . |
|
#6
|
|||
|
|||
|
Just delete any existing copy before making a new copy. You can simply ignore errors if there is no copy, or put in a test to see if the file exists and only delete it if it's already present.
|
|
#7
|
|||
|
|||
|
thx doug, i finally sorted it. i was just hoping for a faster way of doing things but this seems ok now. to kill the file okay u have to make the copy as vbnormal . .
i seen a few posts on how to do this but none with an answer so here it is for anyone looking . . . Code:
FileCopy "c:\log.txt", "c:\logCp.txt"
Dim wdApp As Object
Set wdApp = CreateObject("Word.Application")
wdApp.DisplayAlerts = wdAlertsNone
wdApp.DisplayAlerts = False
FileName = "c:\logCp.txt"
SetAttr FileName, vbNormal
wdApp.Documents.Open FileName, ConfirmConversions:=False, ReadOnly:=False
wdApp.Visible = True
End Sub
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > open word doc without read only error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|