默认情况下,Excel应以只读方式打开,而不显示只读提示

时间:2016-10-06 15:59:11

标签: vbscript

我正在创建一个Excel文件并使用VBScript将文件另存为只读文件。当我手动打开文件时,会出现只读提示。我不想要只读提示我只想让文件在任何用户手动打开文件时以只读方式打开。

1 个答案:

答案 0 :(得分:0)

请试试这个:

excelfile = "Filename of your new excel goes here" 'Example: C:\Documents\TestExcel.xlsx"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
Set book = objExcel.Workbooks.Add()
book.SaveAs(excelfile)
book.Close
objExcel.Quit

Set xf = objFSO.GetFile(excelfile)
If Not xf.Attributes AND 1 Then xf.Attributes = xf.Attributes + 1
MsgBox "Task Complete", vbOKOnly, "Create Read Only Excel"

它直接打开Excel文件为只读,没有任何提示。