VBScript支持在Excel文件中进行编辑并另存为

时间:2018-08-31 07:37:48

标签: vba excel-vba vbscript

Set obj = CreateObject("Excel.Application")
obj.Visible = False
Set objwbk = obj.Workbooks.Open("File Link")
obj.DisplayAlerts = False
objwbk.SaveAs "C:\Data.xlsx"
Set obj1 = obj.Workbooks.Open("C:\Data.xlsx")
obj1.Visible = True

我有上面的代码在SharePoint上创建文件的副本。我能够打开该文件,但由于该文件以只读模式打开,因此无法进行复制。我无法在这里弄清楚如何使用ActiveProtectedWindow.edit方法来成功实现我的目标。

1 个答案:

答案 0 :(得分:0)

也许是这样的:

Set obj = CreateObject("Excel.Application")
obj.Visible = False
obj.DisplayAlerts = False

Set objwbk = obj.Workbooks.Open("File Link")
If objwbk.Application.ProtectedViewWindows.Count > 0 Then
    objwbk.Application.ActiveProtectedViewWindow.Edit
End If
objwbk.SaveAs "C:\Data.xlsx"
Set obj1 = obj.Workbooks.Open("C:\Data.xlsx")
obj1.Visible = True