Count Chars/Words from Comments and TextBox VBA

  • I have the following code that works separately perfect, but when I combined both code parts (comments and text box char/words counting parts) together it pops out the following error WHEN I ADD ANY COMMENT:
    445: Object doesn't support this action
    Line: If TypeName(shp) <> "GroupObject" And shp.TextFrame2.TextRange.Characters.Text <> "" Then



    I cant figure out WHY? I cant imagine any other method than this. Below I have added the combined code. I hope somebody have the right answer to this issue.



    I assume that shp.TextFrame2.TextRange.Characters.Text part made this issue, but why if it works separately? Any suggestions?

  • Re: Count Chars/Words from Comments and TextBox VBA


    Hi,
    Would be easier if you can attach the workbook or sample workbook
    consider ...

  • Re: Count Chars/Words from Comments and TextBox VBA


    Quote from pike;770953


    Hi, Pike.


    I dont understand this part anymore. How it will work with my code? Where to put it?

  • Re: Count Chars/Words from Comments and TextBox VBA


    Without the workbook I cannot tell what controls you have maybe a mix of both active x and form

    Code
    For Each objShape In ActiveSheet.Shapes
         Debug.Print "A~ " & objShape.Name
         Debug.Print "B~ " & TypeName(objShape)
         Debug.Print "C~ " & TypeName(objShape.OLEFormat.Object)
        Next
  • Re: Count Chars/Words from Comments and TextBox VBA


    Quote from pike;770961

    Without the workbook I cannot tell what controls you have maybe a mix of both active x and form

    Code
    For Each objShape In ActiveSheet.Shapes
         Debug.Print "A~ " & objShape.Name
         Debug.Print "B~ " & TypeName(objShape)
         Debug.Print "C~ " & TypeName(objShape.OLEFormat.Object)
        Next


    I have default workbook VBA settings (attached). There is no need to send any workbook - just Insert any 1 comment and 1 TextBox with some added text and then check how many words or chars are there. This part you sent me - I dont know what to do with it to show me msgbox with char/words for comments and textbox's.



    [ATTACH=CONFIG]69165[/ATTACH]

  • Re: Count Chars/Words from Comments and TextBox VBA


    Quote from pike;771014

    No need to look in the frame the text box has unique id or name


    In this case I dont need this unique id/name method, because my goal is to count char/words from ANY TextBox that named with whatever name.

  • Re: Count Chars/Words from Comments and TextBox VBA


    Quote from pike;771084

    all depend what controls are used make a dummy example reflecting the question and attach


    I have added the code on post #1 and I just need the modification that counts char/words from TxtBox and Comments. If I launch code separately (for example only for Comments) its works fine without any controls added. Same situation is with TextBox. I dont add any additional controls. Only that are provided by Default.

  • Re: Count Chars/Words from Comments and TextBox VBA


    best guess

  • Re: Count Chars/Words from Comments and TextBox VBA


    From the post #11. Same error on the line:
    If TypeName(shp) <> "GroupObject" And shp.TextFrame2.TextRange.Characters.Text <> "" Then

  • Re: Count Chars/Words from Comments and TextBox VBA


    Hello,
    Both are shape textboxes but you can determine which type of shape it is by type enumeration
    https://msdn.microsoft.com/en-…rary/office/ff860759.aspx


    https://msdn.microsoft.com/en-…rary/office/ff860759.aspx

  • Re: Count Chars/Words from Comments and TextBox VBA


    and shortened to

  • Re: Count Chars/Words from Comments and TextBox VBA


    Quote from pike;771152

    and shortened [..]
    End Sub[/CODE]


    I didnt think of about type for this part. All looks cool till I encountered it doesnt count TxtBox Words correctly. Now its counts TxtBox as Object. I added 1 text box and it counts as 1 word. No matter how many words are written inside.

  • Re: Count Chars/Words from Comments and TextBox VBA


    Hello,
    if you want to count the words don't use replace space with nothing it just makes it one word . count the spaces like

  • Re: Count Chars/Words from Comments and TextBox VBA


    Quote from pike;771171


    [/CODE]


    WOW. Really WOW. I am impressed. You are like macro magician :wowee:. Now its works as my wall clock.:congrats:

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!