Link to home
Start Free TrialLog in
Avatar of Dale Fye
Dale FyeFlag for United States of America

asked on

Prevent users from saving a file which has been opened via Application.Followhyperlink method

I'm working with a client on an application which will display a list of files which are available for a user to review (file types: pdf, Excel, Word, PPT, Text).

The problem is that after these files are opened:

Application.Followhyperlink pathname\filename

The user has the ability to Save or Save As from the application (Acrobat, Excel, Word, PPT, NotePad, ...) user interface.  Is there any way I can open open the files with some form of command line switch which would prevent any of those applications from allowing the user to even see the File option on the application menu?  I only want them to be able to view and then close these documents.
Avatar of Norie
Norie

Dale

The only way I can think of doing that would be to change the attributes of the file to make it read-only before it's opened.

You could do that using SetAttr.
DIm strPath As String

strPath = "pathname\filename"

SetAttr strPath, vbReadOnly

Application.FollowHyperlink strPath

Open in new window


Of course the user would still be able to save the file under a different name and at some point you would need to reset the file attributes.
<< I only want them to be able to view and then close these documents.>>

 You would have to build your own utility/program to display them.

 For example, a form with a unbound OLE control which only displays the document.

 But with just FollowHyperLink alone, no.

Jim.
Avatar of Dale Fye

ASKER

Jim,

Had not thought about using an OLE control, that might work.

Thanks
You "might" be able to do something with fluent UI customisation but only for Office applications with an extensible backstage and ribbon interface. In the example below, I've hidden the Save and Save As button/tab in the backstage and also repurposed the Save command in the UI so that if the user presses the Save button or hits Ctrl+S, they see the restriction message.

User generated image
Repurposed Save command:

User generated image
Here's the XML for this UI modification:

<customUI onLoad="OnLoad" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
	<commands>
		<command idMso="FileSave" onAction="RepurposeFileSave"/>
	</commands>
	<backstage>
		<button idMso="FileSave" visible="false"/>
		<tab idMso="TabSave" visible="false"/>
	</backstage>
</customUI>

Open in new window


And the callback VBA code:

Option Explicit

Public myRibbon As IRibbonUI

Sub OnLoad(ribbon As IRibbonUI)
  Set myRibbon = ribbon
End Sub

Sub RefreshRibbon()
  myRibbon.Invalidate
End Sub

Sub RepurposeFileSave(control As IRibbonControl, ByRef cancelDefault)
  MsgBox "You can't save this file.", vbInformation + vbOKOnly, "Viewing Mode Only"
  cancelDefault = True
End Sub

Open in new window


Another approach could be to programmatically add a read only password and write password to files and have an add-in pass only the read only password to the hosting application to allow it to be opened but not modified.
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial