Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more: , +
i'm Opening Word File from my Application in HTTP Path
i.e. http:\\Server\SiteName\TempFiles\filename.docx

Word File Showing message as "READ ONLY : This Document is Lock for Editing by another user"

because of this my macro didn't work

Protection = ActiveDocument.ProtectionType
       If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
           ActiveDocument.Unprotect "password"
           WordBasic.AcceptAllChangesInDoc
           ActiveDocument.Protect Protection, False, "password"
           Call updateCustomVariables
           ActiveDocument.Saved = True
           Exit Sub
       End If


every thing is working fine
and still working fine on office (Word) 13,10 machines
this problem suddenly start from last 3- 4 days
i'm getting error as Command failed (Run time Error 4198) for office 16<
no office Updates
no windows update
please help...

What I have tried:

Check trusted Location Setting of Word i.e. Allow documents from Network to be trusted
disable all Protected View options
Posted
Updated 12-Aug-19 18:01pm
v9
Comments
F-ES Sitecore 12-Aug-19 7:27am    
You can't edit files over HTTP like that, it's a read-only medium. When you access a file over http Word is probably downloading it to a temp folder and marking it as locked\read-only, or the OS is doing that.
kedar001 12-Aug-19 23:58pm    
thanks for the reply..
yes i want the file to be read only.but it seems to be locked
the above macro working fine for all office versions
but not i'm getting error as Command failed (Run time Error 4198) for office 16 from last few days for line "ActiveDocument.Unprotect "password""

1 solution

Read the message:
READ ONLY : This Document is Lock for Editing by another user
That means just what it says: the file is in use, and until it is no longer being used you can't access it.

Probably, you app is not closing iot's files properly, and the file remains in use from a "previous incarnation" of you app, or a previous operation within your app.

But there is nothing at all we can do you help you with this: you need to find out where and why - and that means access to yoru code and file system while it's running and we have neither.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
kedar001 12-Aug-19 2:48am    
same document is opening from office 13 or 10
OriginalGriff 12-Aug-19 3:10am    
The chances are that the way MS handle it has changed, given that Word V13 was before the switch to open standard document formats (DOCX instead of DOC) and the locking moving to a separate external file instead of a OS handle lock.
In later versions if your app quits without shutting Word down properly, the lock file can persist and still be there for subsequent runs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900