none
Runtime error 4605 and word application crashing RRS feed

  • Question

  • Hello Everyone,

    I wrote a script to add TAGs as comments of word document. The criteria of adding tag is based on outline numbering as document do not follow word styles, I had to use outline numbering for this purpose.

    There are couple of issues I am facing.

    1.) script is very slow and sometimes my word application crashes.

    2.) sometimes I get a runtime error 4605 'This command is not available' for line "Selection.Comments.Add Range:=Para.Range, text:="[" & sIdLabel & sCurrentNumber & "]" & vbCrLf  ' ID‘}"

    Here is my updated code

    'script to insert TAGs as comment based on word document outline.
    ' The format of TAG is provided by user and also the step by which TAG number need to be incremented
    Public Sub CreateOutline()
        Dim sIdLabel As String
        Dim sCurrentNumber As String
        Dim sStepNumber As String
        Dim Para As Paragraph
       Application.Templates.LoadBuildingBlocks
       'get the TAG format from user.
       sIdLabel = InputBox("Provide the TAG ID", "TS_FS_")
       sCurrentNumber = InputBox("Provide the Current number", "001")
       'get the step by which the TAG number is to be incremented everytime.
       sStepNumber = InputBox("Provide the step", "1")
       For Each Para In ActiveDocument.Paragraphs
          If Para.Range.ListParagraphs.Count = 1 Then
             Para.Range.Select
             Selection.Move wdParagraph, 1
             Selection.Comments.Add Range:=Para.Range, text:="[" & sIdLabel & sCurrentNumber & "]" & vbCrLf  ' ID‘}
             sCurrentNumber = Format(Val(sCurrentNumber) + Val(sStepNumber), String(Len(sCurrentNumber), "0"))
          End If
       Next Para
    End Sub

    Friday, April 10, 2015 7:57 AM

All replies

  • Hi Ashishk15,

    Since you were not able to reproduce the error every time, I suspect this issue maybe relative to the context of document you were handling.

    I am also trying to reproduce this issue in Word 2013 however failed. The code works well for me like figure below:

    >>2.) sometimes I get a runtime error 4605 'This command is not available' for line "Selection.Comments.Add Range:=Para.Range, text:="[" & sIdLabel & sCurrentNumber & "]" & vbCrLf  ' ID‘}"<<

    What's version of Word are you using and the exact error message? Can you add the comment manually? If yes, would you mind sharing with us a reproducible document to help us narrow down this issue. 

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 13, 2015 2:43 AM
    Moderator
  • Hi Fei,

    Thanks for your response. I am using word 2013.

    Yes I am able to add comment manually.

    One issue I found out it when a table comes into a document then I get error 4605. But sometimes I get same error for different reason.

    I'm sorry, how can I share a document? I didn't find a way here to add an attachment.

    • Edited by AshishK15 Monday, April 13, 2015 9:35 AM
    Monday, April 13, 2015 9:32 AM
  • Hi AshishK15,

    >>One issue I found out it when a table comes into a document then I get error 4605. But sometimes I get same error for different reason.<<

    Thanks for the detail explanation for this issue, however I am still failed to reproduce this issue.

    >>how can I share a document?<<

    We can share a document via OneDrive. Please remove the sensitive information before you uploading.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 14, 2015 5:55 AM
    Moderator
  • Hello Fei,

    I have created a word document for reproducing.

    Please download

    https://onedrive.live.com/redir?resid=EB84FBE1B9D8B53B!107&authkey=!AJOqBpaqr47wPwI&ithint=file%2cdocx

    Tuesday, April 14, 2015 8:27 AM
  • Hi AshishK15,

    Thanks for sharing the document, however I am still failed to reproduce the issue.

    When I run the code above, I found there is no list paragraphs in this document. It seems be a character like figure below:

    Would you mind helping to check this document?

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 15, 2015 6:55 AM
    Moderator
  • I have corrected the bullets, it seems to have happened when I copied my document into one drive.

    Regarding runtime error,  I am experiencing it when the execution reaches to the table in the document.

    Wednesday, April 15, 2015 12:35 PM
  • Hi AshishK15,

    Thanks for the correcting. As far as I tested, the code works well for me, I tested both in Office 2013 and Office 2010.

    Which version of Word are you using?

    >> I am experiencing it when the execution reaches to the table in the document<<

    I saw there are several tables in the document however there was no list in the tables. What does "execution reaches to the table" means?

    In addition, I suggest that you try to update the Office to the latest version and repair it to see whether the issue was fixed.

    Hope it is helpful.

    Regards & Fei

     


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Thursday, April 16, 2015 7:22 AM
    Moderator
  • Hi Fei,

    When I run the script in debug mode, I get runtime error when execution reaches to section 1.4 Table1-1.

    I am using office 2013. Tool installation is on a central server in my office and we use thin client to login and access. I believe tool installation has no issues.

    Sometimes for same runtime error 4605 I get a more specific message as 'This method or property is not available because the object refers to the end of a table row'

    The line referred by this error is 'Selection.Comments.Add Range:=Para.Range, text:="[" & sIdLabel & sCurrentNumber & "]" & vbCrLf  ' ID‘}'

    Thursday, April 16, 2015 11:02 AM