Carmi
05-28-2006, 08:45 PM
Hi All - New to VBA doing it mostly for fun (I really do have to get out more!!)
Sorry for the length of my post. I hope that it is descriptive enough to allow readers understand what I want to achieve but hopefully not too long to put readers to sleep :sleep2:
Word 2003 (SP2)
Win XP
I have built a 'Proposal Builder' which allows users within the company to input key criteria into a user form which then pulls together a number of template documents to create a base proposal. The document can then be configured for a particular client, approved by the appropriate manager before being converted to pdf and being sent.
I am looking to develop the tool past the initial creation of the base proposal and provide an 'Approval' process for sign off using the functionality associated with digital certificates.
What I would like to happen is that the document is completed and sent to the relevant manager for approval. Given no changes are required the manger ?Approves? the proposal by adding a self cert digital certificate. Thus as long as the document has the certificate we know it has been formally approved and can be sent.
I realise that there is already the functionality to add a certificate to document and then to have this certificate revoked if there are any changes made to the document. However, these options are somewhat buried and relatively hard for general users to find. Therefore I want to make it easier for people to use?. And then there is the whole fun thing about just learning how to do it. As such I have added the following code to create a custom toolbar which either displays an ?Approved? or ?Not Approved? button depending on the existence of an attached certificate.
The first problem: This works fine when first opening the document with the correct button being displayed. However, if I change the status of the document (i.e from Not Approved to Approved, or from Approved to Not Approved) the button doesn?t automatically update to reflect the correct approval status. I am not sure what the correct event is to update commandbar. Is there anyway to link into the event that causes the name to
The second problem: Trying to add the digital signature I have copied the code directly from the help file. Although this opens the ?Select Certificate? Dialog box it doesn?t add the actual cert. Again I am only using self cert - will this be the cause?
'***Stored in This Document
Option Explicit
Private Sub Document_Close()
'Delete the 'Approval Status'Command bar when the document
'closes so as not be seen by other word docs
On Error Resume Next
CommandBars("Approval Status").Delete
End Sub
Public Sub Document_Open()
'Initial Template Show Input Form
If ThisDocument.Name = "MC5049 - Proposal Builder.doc" Then
UserForm1.Show
Else
'Check to determine if any signature has been added
If ActiveDocument.Signatures.Count > 0 Then
Call approved
Else
Call notApproved
End If
'Need to change the aove code to run only when a certain certicate(s) are added.
'Can this be done on public Key?
End If
End Sub
'***Stored in Module approvalStatus
Option Explicit
Public Sub approved()
Dim myBar As CommandBar
Dim btnApproved As CommandBarButton
'Create command bar
Set myBar = Application.CommandBars.Add("Approval Status")
With myBar
.Position = msoBarFloating
.Left = 50
.Top = 200
.Visible = True
.Enabled = True
End With
'Create button
Set btnApproved = myBar.Controls.Add(Type:=msoControlButton)
With btnApproved
.Caption = "Approved"
.Style = msoButtonIconAndCaption
.FaceId = 1715
.Enabled = True
.Width = 135
.OnAction = "viewSignature"
End With
End Sub
Public Sub notApproved()
Dim myBar As CommandBar
Dim btnNotApproved As CommandBarButton
'Create commandbar
Set myBar = Application.CommandBars.Add("Approval Status")
With myBar
.Position = msoBarFloating
.Left = 50
.Top = 200
.Visible = True
.Enabled = True
End With
'Create Button
Set btnNotApproved = myBar.Controls.Add(Type:=msoControlButton)
With btnNotApproved
.Caption = "Not Approved"
.Style = msoButtonIconAndCaption
.FaceId = 1716
.Enabled = True
.Width = 135
.OnAction = "AddSignature"
End With
End Sub
Sub AddSignature()
'Add Signature. Currently does not work. The Signature is not added?
ActiveDocument.Signatures.Add
End Sub
Sub viewSignature()
Dim sig As Signature
For Each sig In ActiveDocument.Signatures
MsgBox "Approved By:" & " " & sig.signer & vbCr & vbCr _
& "Date Signed:" & " " & sig.SignDate
Next
End Sub
Carmi
Warning: Answering this thread may lead to many more stupid questions... but please answer :yes
Sorry for the length of my post. I hope that it is descriptive enough to allow readers understand what I want to achieve but hopefully not too long to put readers to sleep :sleep2:
Word 2003 (SP2)
Win XP
I have built a 'Proposal Builder' which allows users within the company to input key criteria into a user form which then pulls together a number of template documents to create a base proposal. The document can then be configured for a particular client, approved by the appropriate manager before being converted to pdf and being sent.
I am looking to develop the tool past the initial creation of the base proposal and provide an 'Approval' process for sign off using the functionality associated with digital certificates.
What I would like to happen is that the document is completed and sent to the relevant manager for approval. Given no changes are required the manger ?Approves? the proposal by adding a self cert digital certificate. Thus as long as the document has the certificate we know it has been formally approved and can be sent.
I realise that there is already the functionality to add a certificate to document and then to have this certificate revoked if there are any changes made to the document. However, these options are somewhat buried and relatively hard for general users to find. Therefore I want to make it easier for people to use?. And then there is the whole fun thing about just learning how to do it. As such I have added the following code to create a custom toolbar which either displays an ?Approved? or ?Not Approved? button depending on the existence of an attached certificate.
The first problem: This works fine when first opening the document with the correct button being displayed. However, if I change the status of the document (i.e from Not Approved to Approved, or from Approved to Not Approved) the button doesn?t automatically update to reflect the correct approval status. I am not sure what the correct event is to update commandbar. Is there anyway to link into the event that causes the name to
The second problem: Trying to add the digital signature I have copied the code directly from the help file. Although this opens the ?Select Certificate? Dialog box it doesn?t add the actual cert. Again I am only using self cert - will this be the cause?
'***Stored in This Document
Option Explicit
Private Sub Document_Close()
'Delete the 'Approval Status'Command bar when the document
'closes so as not be seen by other word docs
On Error Resume Next
CommandBars("Approval Status").Delete
End Sub
Public Sub Document_Open()
'Initial Template Show Input Form
If ThisDocument.Name = "MC5049 - Proposal Builder.doc" Then
UserForm1.Show
Else
'Check to determine if any signature has been added
If ActiveDocument.Signatures.Count > 0 Then
Call approved
Else
Call notApproved
End If
'Need to change the aove code to run only when a certain certicate(s) are added.
'Can this be done on public Key?
End If
End Sub
'***Stored in Module approvalStatus
Option Explicit
Public Sub approved()
Dim myBar As CommandBar
Dim btnApproved As CommandBarButton
'Create command bar
Set myBar = Application.CommandBars.Add("Approval Status")
With myBar
.Position = msoBarFloating
.Left = 50
.Top = 200
.Visible = True
.Enabled = True
End With
'Create button
Set btnApproved = myBar.Controls.Add(Type:=msoControlButton)
With btnApproved
.Caption = "Approved"
.Style = msoButtonIconAndCaption
.FaceId = 1715
.Enabled = True
.Width = 135
.OnAction = "viewSignature"
End With
End Sub
Public Sub notApproved()
Dim myBar As CommandBar
Dim btnNotApproved As CommandBarButton
'Create commandbar
Set myBar = Application.CommandBars.Add("Approval Status")
With myBar
.Position = msoBarFloating
.Left = 50
.Top = 200
.Visible = True
.Enabled = True
End With
'Create Button
Set btnNotApproved = myBar.Controls.Add(Type:=msoControlButton)
With btnNotApproved
.Caption = "Not Approved"
.Style = msoButtonIconAndCaption
.FaceId = 1716
.Enabled = True
.Width = 135
.OnAction = "AddSignature"
End With
End Sub
Sub AddSignature()
'Add Signature. Currently does not work. The Signature is not added?
ActiveDocument.Signatures.Add
End Sub
Sub viewSignature()
Dim sig As Signature
For Each sig In ActiveDocument.Signatures
MsgBox "Approved By:" & " " & sig.signer & vbCr & vbCr _
& "Date Signed:" & " " & sig.SignDate
Next
End Sub
Carmi
Warning: Answering this thread may lead to many more stupid questions... but please answer :yes