2013-12-20 42 views
0

我嘗試打開,修改和保存演示文稿,但它總是被開闢爲只讀:VBA:PPT課件演示打開爲只讀

If measTypesDict.Exists(MeasType) = False Then 
    Dim targetPath As String 
    Dim newPres As PowerPoint.presentation 

    measTypesDict.Add MeasType, New Dictionary 

    Set newPres = PowerPoint.Application.Presentations.Add(msoFalse) 

    targetPath = rootDir & "\final\" & MeasType & ".ppt" 
    newPres.SaveAs targetPath 
    ' newPres.Close that is what's been missing 

    targetPresentationsDict.Add MeasType, Presentations.Open(targetPath, ReadOnly:=msoFalse, WithWindow:=msoFalse) 
End If 

Microsoft Documentation

The ReadOnly parameter is used to open a presentation as Read-Only. 
The following example opens a file named test.ppt as Read-Only. 

    Sub OpenPresentationReadOnly() 
     Presentations.Open "c:\test.ppt", msoTrue 
    End Sub 

任何人都可以給我一個提示,爲什麼這是這種情況?我是目標文件夾的所有者,並根據文件夾設置完全控制。

+0

該文件是否已保存爲「只讀」? –

+0

我想我得到了解決方案。我使用'Presentations.Add(msoFalse)'添加了演示文稿,然後保存爲'newPres.SaveAs targetPath'。 **現在**我調用'newPres.Close'並重新打開該演示文稿。現在我有寫入權限 - 但我不太喜歡這個事實,我必須重新打開它。 – displayname

+0

如果您正在執行保存,那麼爲什麼要重新打開它?它已經打開... –

回答

-1

你可以試試這個:

Sub OpenPresentation() 
     Presentations.Open "c:\test.ppt" 
    End Sub 

希望它能幫助。

+0

我想我的腳本做到這一點.. – displayname

+0

@ Stefan.See我更新的答案 –

+0

此成員不存在(http://support.microsoft.com/kb/162555),我認爲你是指Excel的API在這裏。 – displayname