2014-07-10 58 views
1

我有一個Word 2007 docm文件,作爲電子郵件附件發送給用戶,讓他們更新文件。宏從服務器上下載文件並正確安裝它們 - 而不是以電子郵件附件的形式發送文件,並相信用戶能夠正確地安裝它們。我會使用VBScript文件,但我不允許在電子郵件中發送該文件。宏完成時刪除文檔

我想在宏完成時從用戶的計算機中刪除此文檔。但是文檔仍然處於打開狀態,並且該宏在遇到任何Kill或FSO.FileDelete命令時仍在運行。

編輯:找到一種方法讓Word宏創建並啓動VBScript,在文檔關閉並刪除文檔和腳本後觸發。

回答

1

最近的回覆,我知道。

另一種方式來做到這一點的人不熟悉VB腳本可能把這樣的事情在宏的結尾:

Sub DeleteCurrentDoc() 

Dim Doc1 As Document 
Dim Doc2 As Document 
Dim deletepath As String 

'While the document you want to delete is open and is the current 'Active Document' 
Set Doc1 = ActiveDocument 

'get path of this document to delete it later 
deletepath = Doc1.FullName 

'Add a new temporary blank document 
Set Doc2 = Documents.Add 

'Close the document we are going to delete 
Doc1.Close False 

'Delete it 
Kill (deletepath) 

'Clear away the temp doc we created 
Doc2.Close False 

'Tidy up and close Word (Optional Line, delete if necessary) 
Application.Quit 

End Sub 

編輯:一種更輕的方式(測試字2013):

Sub DeleteCurrentDoc() 

Dim Doc1 As Document 
Dim deletepath As String 


'get path of this document to delete it later 
deletepath = ActiveDocument.FullName 

'Close the document we are going to delete (Word should remain Open 
ActiveDocument.Close False 

'Delete it 
Kill (deletepath) 

'Tidy up and close Word (Optional Line, delete if necessary) 
Application.Quit 

End Sub