Solved

Launching Word Document as readonly

Posted on 2002-03-06
11
450 Views
Last Modified: 2010-08-05
I want to launch a word document as readonly so the user can't update it.  But I really don't want to mark the document file as readonly.

I can do this by using the word object, ie:

Sub LaunchDoc(byval DocName)
  Dim oW as Word.Application
  Set oW = new Word.Application
  ow.Open Docname,ReadOnly:=True
  .
  .
  .
end sub

But for techinal reasons, I need to be able to launch this Doc by executing Word ie:

ret=Shell(WinWord & " " & DocName)


My problem is that there are no switches that will make word open the doc as readonly.  Again, I prefer not to mark the Doc file as readonly.

Any ideas?
0
Comment
Question by:khampton
11 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
can you create a copy of your docname to another name and mark this copy as read-only?
0
 
LVL 3

Expert Comment

by:tonydspaniard
Comment Utility
You can create a temporary read-only file.... then use the shell function to open it.... use API to speed up the process.

CYA
0
 
LVL 1

Author Comment

by:khampton
Comment Utility
Creating a copy and marking it as readonly is not a workable option for me:

1) I'm using Word in an Intranet application.  This means I'm limited to using JavaScript or VBScript.  Because of the warnings that the IExplorer gives, I can't really use Word as an object. (Its true that I could write an ActiveX.dll and encapselate the operation and mark it safe for the internet but that is far, far too much work for this app.)

2) I can't use API's in JavaScript or VBScript.

3) Making a temp copy of a document (some of which are very, very long) and then destroying it afterwards is far too much overhead for this application.
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi khampton ,since i can't find any commandline switches doing this, it leaves nothing more to add to the current suggestions except for a little macro to the word document

and then adding to your commandline /m<macroname>

this little macro doesn't do anything then open the document as read-only

:O)Bruintje
0
 
LVL 1

Author Comment

by:khampton
Comment Utility
bruintje -

That is what I thought was needed.  Problem is I am not well versed on macros...

1) Do I store the macro in a template?  (.dot?)

2) Can I have this template reside on the server?

3) Would you show me the code to do this?

Mucho Gracias...
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi Khampton,

wasn't that straightforward.....since there's no switch a little script

-open word
-form new | choose blank document | open as template
-bring up the VB Editor with ALT+F11
-look for the thisdocument icon under teh current template project NOT the normal.dot
-paste the code

<code>

Option Explicit

Private Sub Document_New()
Dim strYourDoc As String
Dim strTemplateName As String
  Application.ScreenUpdating = False
  ' get template based document name
  strTemplateName = ActiveDocument.Name
  ' set name of your document
  strYourDoc = "\\serverpath\yourdoc.doc"
  ' open your document as read only
  Documents.Open FileName:=strYourDoc, ReadOnly:=True
  ' close this template based empty doc
  Documents(strTemplateName).Close
  Application.ScreenUpdating = True
End Sub

</code>

-replace the string of strYourDoc with another document you would like to open read-only
-now save the template as yourname.dot on the server
-save in the same directory the strYourDoc document
-and then you can open the template
-it will open the stryourdoc as read only and close itself so the user won't notice

HTH:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
Hi khampton, did it help?
0
 
LVL 1

Author Comment

by:khampton
Comment Utility
bruintie:

Sorry, I've been away on vacation.  I will try your suggestion in the next day our two...

Thanks.
0
 
LVL 1

Author Comment

by:khampton
Comment Utility
Dear bruintie,

Your solution requires that I know the name of the document in advance and it must be "hardcoded".

Do you know of a way that I can develope a generic solution?

For example, do you know how to create a template, lets call it: ProtectMe.dot

When word is shelled, I would then include the DocName and add a /m "...\ProtectMe.dot"  

ProtectMe.dot would then change the document to be readonly.

If that strategy can't work (because the document is opened prior to applying the template logic) then how about this:

I would shell word with the template name and include the Path\DocName.doc to be opened.  The template would grab the DocName from the commandline (?? is this possible??) and then open the doc as readonly.

Anyway, I am not well versed on macros or VBA as it relates to Word.  I would appreciate your expertise in this area.

I will increase the points if you can give me a detailed solution.

Thanks very much!
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Hi khampton,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

khampton, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
Comment Utility
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now