Al 95% ,falla Excel ,Ok en Word i PPT Bueno ,me voy respondiendo a mi mismo ,aqui teneis casi una solucion total para este tema. Espero que alguien le pueda ayudar, y si alguiem me puede dar una solucion para los archivos excel pues mejor ,pues en este tipo de archivo no se como puedo poner la firma digital.
Gracias..
------------------
AddSign ,le pasamos el documento a firmar, y un entero diciendo el tipo de fichero ,1 Word ,2 Excel (el que me falla) ,3 PPT
Referencias, Ms Office 11.0 Object Library ,lo mismo en Word ,Excel y Power Point, Tambien las capicom y no se si me olvido de alguna otra.
-----------------
Public Sub AddDigSig(docu As String, tipus As Integer)
'Declare the object and data type that will be used.
Dim bAddSig As Boolean
'*** note that this should be defined fully, possibly as Word.Signature
Dim sig As Office.Signature
Dim wordapp As Word.Application
Dim worddoc As Word.Document
Dim pptapp As PowerPoint.Application
Dim pptdoc As PowerPoint.Presentation
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
'When there is an error, go to Error_Handler for error handling.
On Error GoTo Error_Handler
Select Case tipus '"select case" is like if, but you can check multiple values
Case 1
Set wordapp = CreateObject("Word.Application")
Set worddoc = wordapp.Documents.Open(docu)
wordapp.Visible = True
Set sig = worddoc.Signatures.Add
Case 2
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(docu)
xlApp.Visible = True
Set sig = ActiveDocument.Signatures.Add
'not sure if this is right:
' Set sig = xlBook.Signatures.Add
'may need to be this instead:
'Set xlSheet = xlBook.Worksheets(1)
'Set sig = xlSheet.Signatures.Add
Case 3
Set pptapp = CreateObject("PowerPoint.Application")
pptapp.WindowState = ppWindowMinimized
pptapp.Visible = True
Set pptdoc = pptapp.Presentations.Open(docu)
pptapp.Visible = True
Set sig = pptdoc.Signatures.Add
End Select
'Check the validity of the digital certificate used for signing.
'If it hasn't expired AND not revoked, then set bAddSig to True.
If sig.IsCertificateExpired = False And _
sig.IsCertificateRevoked = False Then
bAddSig = True
Else
'If it isn't valid, delete the signature on the document.
sig.Delete
bAddSig = False
End If
'Commit the signature. Until the Commit method is executed,
'none of the changes to the SignatureSet collection are saved.
If tipus = 1 Then
worddoc.Signatures.Commit
Set sig = Nothing
worddoc.Close SaveChanges:=True
Set worddoc = Nothing
wordapp.Quit
Set wordapp = Nothing
Else
If tipus = 3 Then
pptdoc.Signatures.Commit
Set sig = Nothing
pptdoc.Close
' pptdoc.Close SaveChanges:=True
Set pptdoc = Nothing
pptapp.Quit
Set pptapp = Nothing
End If
End If
'Clean up by destroying the sig object now that it isn't needed anymore.
'*** save and close the document
Exit Sub
Error_Handler:
MsgBox "Document signing action has been cancelled."
MsgBox "Se ha producido el siguiente error:" & vbCrLf & _
Err.Number & ", " & Err.Description
Set sig = Nothing
'*** close (but dont save) the document
If tipus = 1 Then
worddoc.Close SaveChanges:=False
wordapp.Quit
Set wordapp = Nothing
Else
If tipus = 3 Then
pptdoc.Close
pptapp.Quit
Set pptapp = Nothing
End If
End If
End Sub |