|
-
Apr 28th, 2022, 08:42 AM
#1
Thread Starter
Junior Member
vb. Net how to capture the save () event of word?
I use VB.Net calls word2010 in com mode, but how to capture the save () event of word
-
Apr 28th, 2022, 09:27 AM
#2
Re: vb. Net how to capture the save () event of word?
VB.NET Code:
Private _word As Word.Application
...
' Get or create Word application object
_word = ...
AddHandler _word.DocumentBeforeSave, AddressOf DocumentBeforeSave
...
Private Sub DocumentBeforeSave(Doc As Word.Document, ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean)
Debug.Print(Doc.Name)
Cancel = False
End Sub
-
May 1st, 2022, 11:40 PM
#3
Thread Starter
Junior Member
Re: vb. Net how to capture the save () event of word?
 Originally Posted by peterst
VB.NET Code:
Private _word As Word.Application
...
' Get or create Word application object
_word = ...
AddHandler _word.DocumentBeforeSave, AddressOf DocumentBeforeSave
...
Private Sub DocumentBeforeSave(Doc As Word.Document, ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean)
Debug.Print(Doc.Name)
Cancel = False
End Sub
Thank you. It works.
Unfortunately, word has no documentaftersave event.
Well, I want to use VB immediately after the document is saved Net code saves the document to the BLOB field of the data table.
-
May 2nd, 2022, 01:12 AM
#4
Re: vb. Net how to capture the save () event of word?
Inside DocumentBeforeSave event management you have to simulate what Word do and you will have to do the save yourself so you can catch it. Something like this:
VB.NET Code:
Private _saveActive As Boolean = False
Private Sub DocumentBeforeSave(Doc As Word.Document, ByRef SaveAsUI As Boolean, ByRef Cancel As Boolean)
If _saveActive Then
Return ' If save is active then just return
End If
_saveActive = True
If SaveAsUI Then
' Show UI when SaveAs or new file is saved - needs user interaction to select file
Dim saveDialog = _word.Dialogs.Item(Word.WdWordDialog.wdDialogFileSaveAs)
saveDialog.Show()
Else
Doc.Save()
End If
Dim filename = Doc.FullName ' Grab the file name of the document
'
' Do whatever you want with the file - upload to network storage, save in db BLOB, ...
'
_saveActive = False
Cancel = True ' Cancel the save operation as document was just saved
End Sub
If file is new or SaveAs is performed, it is required some user interaction to select destination file name so save dialog is shown. In the other case when no UI is required, the save is just performed. Then you can get from Word.Document object the file name and do whatever you want.
-
May 2nd, 2022, 09:03 AM
#5
Thread Starter
Junior Member
Re: vb. Net how to capture the save () event of word?
Thank you. I see. It is to execute the save method in the documentbeforesave event
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|