Skip to content

Instantly share code, notes, and snippets.

@yoshimov
Created September 30, 2011 09:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshimov/1253177 to your computer and use it in GitHub Desktop.
Save yoshimov/1253177 to your computer and use it in GitHub Desktop.
Windows Script to open Office files with read only.
Dim strFileName, strExt
Dim objApp
'Check arguments
If WScript.Arguments.Count <> 1 Then WScript.Quit
'get file name
strFileName = WScript.Arguments(0)
strExt = LCase(Right(strFileName, 4))
Select Case strExt
Case "pptx", ".ppt"
'open powerpoint
Set objApp = WScript.CreateObject("Powerpoint.Application")
objApp.Visible = True
'open file with read only
Call objApp.Presentations.Open(strFileName,True)
Case "docx", ".doc"
'open word
Set objApp = WScript.CreateObject("Word.Application")
objApp.Visible = True
'open file with read only
Call objApp.Documents.Open(strFileName,,True)
Case "xlsx", ".xls"
'open excel
Set objApp = WScript.CreateObject("Excel.Application")
objApp.Visible = True
'open file with read only
Call objApp.Workbooks.Open(strFileName,,True)
End Select
'finish
Set objApp = Nothing
WScript.Quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment