none
How to add a shape that having self-defined behaviour into Word within my addin? RRS feed

  • Question

  • Hi,

    I want to make a Word addin to check if the document was changed since last save, and who changed it. So I need to add a shape whose tooltip show the modifier's name and right menu to decide if the shape can be print out, any suggestions?

    I also consider to create an object for Word, just like activex for IE. But I have no idear which kind of object does word supportted, and how to add it by addin?

    Thanks.


    Feel free


    • Edited by 湯 宗磊 Wednesday, April 18, 2012 8:09 AM
    Wednesday, April 18, 2012 7:43 AM

Answers

  • Hi,

    As I understand, your requirement covers two parts, one is to detect if an active open document is changed, another is to show the modifier's name in a shape. I'm going to comment accordingly:

    • detect if an active open document is changed.  This example asks the user whether to save all the other open documents when the document focus changes. This code must be placed in a class module, and an instance of the class must be correctly initialized to see this example work; see Using Events with the Application Object for directions on how to accomplish this.
    Public WithEvents appWord as Word.Application 
     
    Private Sub appWord_DocumentChange() 
     Dim intResponse As Integer 
     Dim strName As String 
     Dim docLoop As Document 
     
     intResponse = MsgBox("Save all other documents?", vbYesNo) 
     
     If intResponse = vbYes Then 
     strName = ActiveDocument.Name 
     For Each docLoop In Documents 
     With docLoop 
     If .Name <> strName Then 
     .Save 
     End If 
     End With 
     Next docLoop 
     End If 
    End Sub

    • show the modifier's name in a shape.  You can get last modifier name by ActiveDocument.BuiltInDocumentProperties collection.  A list of property can be retrieved by below VBA code:
       
    Sub showBuiltinDocumentProperties()
    
    For Each proDoc In ActiveDocument.BuiltInDocumentProperties
     With rngDoc
     MsgBox (proDoc.Name)
     MsgBox proDoc.Value
     On Error Resume Next
     
     End With
     Next
    
    
    
    End Sub

    Note:

    In case you don't want to open document, but just check change between last two save, that's version control feature, you may need to use Sharepoint in this case. Above code doesn't apply.

    Hope this gets you started.


    Forrest Guo | MSDN Community Support | Feedback to manager

    • Marked as answer by 湯 宗磊 Friday, April 20, 2012 5:51 AM
    Friday, April 20, 2012 1:56 AM
    Moderator

All replies

  • Hi 湯 宗磊,

    I will involve other engineers to see whether they can give you some suggestions about the problem. There might be some delay about the response. Appreciate your patience.
    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, April 19, 2012 5:11 AM
  • Hi,

    As I understand, your requirement covers two parts, one is to detect if an active open document is changed, another is to show the modifier's name in a shape. I'm going to comment accordingly:

    • detect if an active open document is changed.  This example asks the user whether to save all the other open documents when the document focus changes. This code must be placed in a class module, and an instance of the class must be correctly initialized to see this example work; see Using Events with the Application Object for directions on how to accomplish this.
    Public WithEvents appWord as Word.Application 
     
    Private Sub appWord_DocumentChange() 
     Dim intResponse As Integer 
     Dim strName As String 
     Dim docLoop As Document 
     
     intResponse = MsgBox("Save all other documents?", vbYesNo) 
     
     If intResponse = vbYes Then 
     strName = ActiveDocument.Name 
     For Each docLoop In Documents 
     With docLoop 
     If .Name <> strName Then 
     .Save 
     End If 
     End With 
     Next docLoop 
     End If 
    End Sub

    • show the modifier's name in a shape.  You can get last modifier name by ActiveDocument.BuiltInDocumentProperties collection.  A list of property can be retrieved by below VBA code:
       
    Sub showBuiltinDocumentProperties()
    
    For Each proDoc In ActiveDocument.BuiltInDocumentProperties
     With rngDoc
     MsgBox (proDoc.Name)
     MsgBox proDoc.Value
     On Error Resume Next
     
     End With
     Next
    
    
    
    End Sub

    Note:

    In case you don't want to open document, but just check change between last two save, that's version control feature, you may need to use Sharepoint in this case. Above code doesn't apply.

    Hope this gets you started.


    Forrest Guo | MSDN Community Support | Feedback to manager

    • Marked as answer by 湯 宗磊 Friday, April 20, 2012 5:51 AM
    Friday, April 20, 2012 1:56 AM
    Moderator
  • Hi,

    Thanks for your reply, that's helped alot.


    Feel free

    Friday, April 20, 2012 5:51 AM