Results 1 to 11 of 11

Thread: 462 and others errors with Word

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    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:
    1. Public Sub AddDigSig()
    2.  'Declare the object and data type that will be used.
    3. Dim bAddSig As Boolean
    4. Dim sig As Signature
    5. Dim wordapp As Word.Application
    6.  
    7.    
    8.    'When there is an error, go to Error_Handler for error handling.
    9.    On Error GoTo Error_Handler
    10.      
    11.     Set wordapp = CreateObject("Word.Application")
    12.     wordapp.Documents.Open ("c:\word\hola.doc")
    13.     wordapp.Visible = True
    14.    
    15.     Set sig = ActiveDocument.Signatures.Add
    16.    
    17.    
    18.    'Check the validity of the digital certificate used for signing.
    19.    'If it hasn't expired AND not revoked, then set bAddSig to True.
    20.     If sig.IsCertificateExpired = False And _
    21.        sig.IsCertificateRevoked = False Then
    22.            
    23.       bAddSig = True
    24.     Else
    25.       'If it isn't valid, delete the signature on the document.
    26.        sig.Delete
    27.        bAddSig = False
    28.     End If
    29.    
    30.    'Commit the signature. Until the Commit method is executed,
    31.    'none of the changes to the SignatureSet collection are saved.
    32.    ActiveDocument.Signatures.Commit
    33.    
    34.    'Clean up by destroying the sig object now that it isn't needed anymore.
    35.    Set sig = Nothing
    36.    'wordApp.Documents.Close ("c:\word\hola.doc")
    37.    wordapp.Quit
    38.    Set wordapp = Nothing
    39.    
    40.    
    41. Exit Sub
    42.  
    43. Error_Handler:
    44.      MsgBox "Document signing action has been cancelled."
    45.      Set sig = Nothing
    46.      wordapp.Quit
    47.      Set wordapp = Nothing
    48. End Sub
    49.  
    50.  
    51. Public Sub DigSigValid()
    52.  
    53.    'Declare the objects and data type that will be used.
    54.    Dim sSigValid As String
    55.    Dim objSignature As Signature
    56.    Dim wordapp As Word.Application
    57.    
    58.  
    59.    'When there is an error, go to Error_Handler for error handling.
    60.    On Error GoTo Error_Handler
    61.  
    62.    'Check all of the signatures
    63.    sSigValid = ""
    64.      
    65.    Set wordapp = CreateObject("Word.Application")
    66.    wordapp.Documents.Open ("c:\word\hola.doc")
    67.    wordapp.Visible = True
    68.  
    69.    For Each objSignature In ActiveDocument.Signatures
    70.        sSigValid = sSigValid + "Is Signature from: " + objSignature.Signer _
    71.        + " Valid?: " + Str$(objSignature.IsValid) + vbCrLf
    72.    Next objSignature
    73.  
    74.    MsgBox (sSigValid)
    75.    Set objSignature = Nothing
    76.    wordapp.Quit
    77.    Set wordapp = Nothing
    78. Exit Sub
    79.  
    80. Error_Handler:
    81.    MsgBox "An error has occurred while trying to validate the digital signature. Please try running the DigSigValid macro again."
    82.    Set objSignature = Nothing
    83.    wordapp.Quit
    84.    Set wordapp = Nothing
    85. End Sub
    Last edited by si_the_geek; Nov 7th, 2005 at 02:56 PM. Reason: added VBCode tags

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. Public Sub AddDigSig()
    2.  'Declare the object and data type that will be used.
    3. Dim bAddSig As Boolean
    4.  
    5. '*** note that this should be defined fully, [i]possibly[/i] as Word.Signature
    6. Dim sig As Signature    
    7. Dim wordapp As Word.Application
    8. Dim worddoc as Word.Document
    9.    
    10.    'When there is an error, go to Error_Handler for error handling.
    11.    On Error GoTo Error_Handler
    12.      
    13.     Set wordapp = CreateObject("Word.Application")
    14.     Set worddoc = wordapp.Documents.Open ("c:\word\hola.doc")
    15.     wordapp.Visible = True
    16.    
    17.     Set sig = worddoc.Signatures.Add
    18.    
    19.    'Check the validity of the digital certificate used for signing.
    20.    'If it hasn't expired AND not revoked, then set bAddSig to True.
    21.     If sig.IsCertificateExpired = False And _
    22.        sig.IsCertificateRevoked = False Then
    23.            
    24.       bAddSig = True
    25.     Else
    26.       'If it isn't valid, delete the signature on the document.
    27.        sig.Delete
    28.        bAddSig = False
    29.     End If
    30.    
    31.    'Commit the signature. Until the Commit method is executed,
    32.    'none of the changes to the SignatureSet collection are saved.
    33.    worddoc.Signatures.Commit
    34.    
    35.    'Clean up by destroying the sig object now that it isn't needed anymore.
    36.    Set sig = Nothing
    37.  
    38. '***  save and close the document
    39.    worddoc.Close SaveChanges := True
    40.    Set worddoc = Nothing
    41.    wordapp.Quit
    42.    Set wordapp = Nothing
    43.    
    44. Exit Sub
    45.  
    46. Error_Handler:
    47.      MsgBox "Document signing action has been cancelled."
    48.      Set sig = Nothing
    49. '***  close (but dont save) the document
    50.      worddoc.Close SaveChanges := False
    51.      wordapp.Quit
    52.      Set wordapp = Nothing
    53. End Sub
    54.  
    55.  
    56. Public Sub DigSigValid()
    57.  
    58.    'Declare the objects and data type that will be used.
    59.    Dim sSigValid As String
    60.    Dim objSignature As Signature
    61.    Dim wordapp As Word.Application
    62.    Dim worddoc as Word.Document
    63.  
    64.    'When there is an error, go to Error_Handler for error handling.
    65.    On Error GoTo Error_Handler
    66.  
    67.    'Check all of the signatures
    68.    sSigValid = ""
    69.      
    70.    Set wordapp = CreateObject("Word.Application")
    71.    Set worddoc = wordapp.Documents.Open ("c:\word\hola.doc")
    72.    wordapp.Visible = True
    73.  
    74.    For Each objSignature In worddoc.Signatures
    75.        sSigValid = sSigValid + "Is Signature from: " + objSignature.Signer _
    76.        + " Valid?: " + Str$(objSignature.IsValid) + vbCrLf
    77.    Next objSignature
    78.  
    79.    MsgBox (sSigValid)
    80.    Set objSignature = Nothing
    81. '***  close (but dont save) the document
    82.    worddoc.Close SaveChanges := False
    83.    Set worddoc = Nothing
    84.    wordapp.Quit
    85.    Set wordapp = Nothing
    86. Exit Sub
    87.  
    88. Error_Handler:
    89.    MsgBox "An error has occurred while trying to validate the digital signature. Please try running the DigSigValid macro again."
    90.    Set objSignature = Nothing
    91. '***  close (but dont save) the document
    92.      worddoc.Close SaveChanges := False
    93.    wordapp.Quit
    94.    Set wordapp = Nothing
    95. End Sub
    [/QUOTE]

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    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.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. 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)

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    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

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: thanks again and question

    Something like this I'd guess (signature part untested!):
    VB Code:
    1. Dim wordapp As Word.Application
    2. Dim worddoc As Word.Document
    3. Dim pptapp As PowerPoint.Application
    4. Dim pptdoc As PowerPoint.Presentation
    5. Dim xlApp as Excel.Application
    6. Dim xlBook as Excel.WorkBook
    7. 'Dim xlSheet as Excel.WorkSheet  '(may be needed)
    8.  
    9.     Select Case tipus   '"select case" is like if, but you can check multiple values
    10.     Case 1
    11.         Set wordapp = CreateObject("Word.Application")
    12.         Set worddoc = wordapp.Documents.Open(docu)
    13.         wordapp.Visible = True
    14.         Set sig = worddoc.Signatures.Add
    15.     Case 2
    16.         Set pptapp = CreateObject("PowerPoint.Application")
    17.         pptapp.WindowState = ppWindowMinimized
    18.         pptapp.Visible = True
    19.         Set pptdoc = pptapp.Presentations.Open(docu)
    20.         pptapp.Visible = True
    21.         Set sig = pptdoc.Signatures.Add
    22.     Case 3
    23.         Set xlApp = CreateObject("Excel.Application")
    24.         Set xlBook = xlApp.WorkBooks.Open(docu)
    25.         xlApp.Visible = True
    26.           'not sure if this is right:
    27.         Set sig = xlBook.Signatures.Add
    28.            'may need to be this instead:
    29.         'Set xlSheet = xlBook.Worksheets(1)
    30.         'Set sig = xlSheet.Signatures.Add
    31.     End Select

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    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???

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  9. #9

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    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.

  10. #10

    Thread Starter
    Member
    Join Date
    Oct 2005
    Posts
    48

    problems with sign excel files

    Hi,

    Another idea, to sign excel files?

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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
  •  



Click Here to Expand Forum to Full Width