|
-
Nov 7th, 2005, 03:24 AM
#1
Thread Starter
Member
462 and others errors with Word
Hi ,i have got 462 error with word creating objects , this is my code:
AddDigSig--> Put in a word document a sign
DigSigValid --> Try to verifiy the document file
Errors:
AddDigSig : It's really strange ,the firts time run's ok but the second ,say 462 error and "Can not complete this actions, becasue the other aplicactions is byst, try change to activate the busy aplication and try to fix it" ,sorry for my inglish.
And the most strange is it the wordapp.Visible = True ,have to be in true ,it's false direct say "Can not complete...."
DigSigValid: Always say de msgbox ,telling if its signed or not ,and after the 462 error.
I thinks that a typical createdobjected error ,i tryed to read old post that write about it , but i can fix it.
All help will be apreciated, and thanks to everybody.
-------------------------------
VB Code:
Public Sub AddDigSig()
'Declare the object and data type that will be used.
Dim bAddSig As Boolean
Dim sig As Signature
Dim wordapp As Word.Application
'When there is an error, go to Error_Handler for error handling.
On Error GoTo Error_Handler
Set wordapp = CreateObject("Word.Application")
wordapp.Documents.Open ("c:\word\hola.doc")
wordapp.Visible = True
Set sig = ActiveDocument.Signatures.Add
'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.
ActiveDocument.Signatures.Commit
'Clean up by destroying the sig object now that it isn't needed anymore.
Set sig = Nothing
'wordApp.Documents.Close ("c:\word\hola.doc")
wordapp.Quit
Set wordapp = Nothing
Exit Sub
Error_Handler:
MsgBox "Document signing action has been cancelled."
Set sig = Nothing
wordapp.Quit
Set wordapp = Nothing
End Sub
Public Sub DigSigValid()
'Declare the objects and data type that will be used.
Dim sSigValid As String
Dim objSignature As Signature
Dim wordapp As Word.Application
'When there is an error, go to Error_Handler for error handling.
On Error GoTo Error_Handler
'Check all of the signatures
sSigValid = ""
Set wordapp = CreateObject("Word.Application")
wordapp.Documents.Open ("c:\word\hola.doc")
wordapp.Visible = True
For Each objSignature In ActiveDocument.Signatures
sSigValid = sSigValid + "Is Signature from: " + objSignature.Signer _
+ " Valid?: " + Str$(objSignature.IsValid) + vbCrLf
Next objSignature
MsgBox (sSigValid)
Set objSignature = Nothing
wordapp.Quit
Set wordapp = Nothing
Exit Sub
Error_Handler:
MsgBox "An error has occurred while trying to validate the digital signature. Please try running the DigSigValid macro again."
Set objSignature = Nothing
wordapp.Quit
Set wordapp = Nothing
End Sub
Last edited by si_the_geek; Nov 7th, 2005 at 02:56 PM.
Reason: added VBCode tags
-
Nov 7th, 2005, 03:02 PM
#2
Re: 462 and others errors with Word
I would strongly recommend using an object varaible for the document, as this will allow you close it (which may solve the problem), and will eliminate issues with the ActiveDocument changing (when the user opens a Word document for example).
eg:
VB Code:
Public Sub AddDigSig()
'Declare the object and data type that will be used.
Dim bAddSig As Boolean
'*** note that this should be defined fully, [i]possibly[/i] as Word.Signature
Dim sig As Signature
Dim wordapp As Word.Application
Dim worddoc as Word.Document
'When there is an error, go to Error_Handler for error handling.
On Error GoTo Error_Handler
Set wordapp = CreateObject("Word.Application")
Set worddoc = wordapp.Documents.Open ("c:\word\hola.doc")
wordapp.Visible = True
Set sig = worddoc.Signatures.Add
'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.
worddoc.Signatures.Commit
'Clean up by destroying the sig object now that it isn't needed anymore.
Set sig = Nothing
'*** save and close the document
worddoc.Close SaveChanges := True
Set worddoc = Nothing
wordapp.Quit
Set wordapp = Nothing
Exit Sub
Error_Handler:
MsgBox "Document signing action has been cancelled."
Set sig = Nothing
'*** close (but dont save) the document
worddoc.Close SaveChanges := False
wordapp.Quit
Set wordapp = Nothing
End Sub
Public Sub DigSigValid()
'Declare the objects and data type that will be used.
Dim sSigValid As String
Dim objSignature As Signature
Dim wordapp As Word.Application
Dim worddoc as Word.Document
'When there is an error, go to Error_Handler for error handling.
On Error GoTo Error_Handler
'Check all of the signatures
sSigValid = ""
Set wordapp = CreateObject("Word.Application")
Set worddoc = wordapp.Documents.Open ("c:\word\hola.doc")
wordapp.Visible = True
For Each objSignature In worddoc.Signatures
sSigValid = sSigValid + "Is Signature from: " + objSignature.Signer _
+ " Valid?: " + Str$(objSignature.IsValid) + vbCrLf
Next objSignature
MsgBox (sSigValid)
Set objSignature = Nothing
'*** close (but dont save) the document
worddoc.Close SaveChanges := False
Set worddoc = Nothing
wordapp.Quit
Set wordapp = Nothing
Exit Sub
Error_Handler:
MsgBox "An error has occurred while trying to validate the digital signature. Please try running the DigSigValid macro again."
Set objSignature = Nothing
'*** close (but dont save) the document
worddoc.Close SaveChanges := False
wordapp.Quit
Set wordapp = Nothing
End Sub
[/QUOTE]
-
Nov 8th, 2005, 03:13 AM
#3
Thread Starter
Member
Re: 462 and others errors with Word
Thanks,
All that i can say is thanks ,
A question, i saw that you say:
'*** note that this should be defined fully, possibly as Word.Signature
Dim sig As Signature
Dim wordapp As Word.Application
Dim worddoc as Word.Document
-----
I tryed to do dim sig as word.signature, but doesn't exist, a propiety from word that is a signature.
-
Nov 8th, 2005, 05:58 AM
#4
Re: 462 and others errors with Word
No problem 
I just had a little search at the MS website, and found that it is part of the "Office" library, and as such should be defined as:
VB Code:
Dim sig As Office.Signature
Note that this wont actually make any difference, as the definition in code at the MS site always defines it just as Signature (it's just good programming practice to specify, as theoretically there could be another type of object called Signature)
-
Nov 8th, 2005, 11:25 AM
#5
Thread Starter
Member
thanks again and question
I tryed the last post ,and word ok ,thanks ,but i thought that was the same with ppt and excel files, and not. I found what i have to do with ppt files ,but i can't do with excel files , i put what i have done:
Tipus it's a varible that it's 1 if it's a doc document, 3 if it's a ppt presentation and 2 for excel.
Dim wordapp As Word.Application
Dim worddoc As Word.Document
Dim pptapp As PowerPoint.Application
Dim pptdoc As PowerPoint.Presentation
If tipus = 1 Then
Set wordapp = CreateObject("Word.Application")
Set worddoc = wordapp.Documents.Open(docu)
wordapp.Visible = True
Set sig = worddoc.Signatures.Add
Else
If tipus = 2 Then
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
else
if tipus=3 then ?????
endif
End If
Can you help me again???
Thanks
-
Nov 8th, 2005, 01:17 PM
#6
Re: thanks again and question
Something like this I'd guess (signature part untested!):
VB Code:
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 '(may be needed)
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 pptapp = CreateObject("PowerPoint.Application")
pptapp.WindowState = ppWindowMinimized
pptapp.Visible = True
Set pptdoc = pptapp.Presentations.Open(docu)
pptapp.Visible = True
Set sig = pptdoc.Signatures.Add
Case 3
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.WorkBooks.Open(docu)
xlApp.Visible = True
'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
End Select
-
Nov 9th, 2005, 02:42 AM
#7
Thread Starter
Member
Thanks but not work
Thanks now, the code it's more clean ,but continues without working the excel sign documents. I Tryed two ways ,with xlbook.signatures and xlsheet.signatures ,but this propiety does not exist with them. So how i can do it???
-
Nov 9th, 2005, 01:07 PM
#8
Re: 462 and others errors with Word
I have an old version of Office here, so I'm afraid I don't have the ability to add signatures.
I have found a couple of pages on the MS support site which explain how to do it, the first is for Excel 2003, and the second is for Excel 2002 (but doesn't seem to load properly!):
http://support.microsoft.com/default...b;en-us;820738
http://support.microsoft.com/kb/288985/EN-US/
The 2003 page explains how to do it manually, but not the code for it - however if you record a macro while you are doing it manually then hopefully (like with other actions in Excel) it will write the code to the macro for you. You can then modify it to your needs; I can help 'translate' the macro code if you need me to.
-
Nov 10th, 2005, 03:13 AM
#9
Thread Starter
Member
Re: 462 and others errors with Word
Hi,
I tryed record a macro ,with excel ,but the digital sign it's disables when i try to record, i used a Excel 2003 and a Xp version ,and also it's the same. So it's impossible to record using digital sign.
-
Nov 23rd, 2005, 04:50 AM
#10
Thread Starter
Member
problems with sign excel files
Hi,
Another idea, to sign excel files?
-
Nov 23rd, 2005, 12:10 PM
#11
Re: 462 and others errors with Word
I haven't got any ideas myself, but I know someone who might - I'll ask them to have a look at this thread.
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
|