Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Lounger
    Join Date
    Apr 2009
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi ,

    I am editing one document and I would like all the passive sentences (basically having "by" in them) to get collated in one documen.
    Can we create a macro for this , i have tried doing this but it is not automatic i have to first record the macro for this purpose and then use it. (no point creating it).

    Can i have some way of doing it automatically.

    Regards,
    techwriter

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Does this do what you want?

    Code:
    Sub ExtractSentencesWithBy()
      Dim docSrc As Document
      Dim docTrg As Document
      Dim rng As Range
      Set docSrc = ActiveDocument
      Set docTrg = Documents.Add
      For Each rng In docSrc.Sentences
    	If InStr(rng.Text, " by ") > 0 Then
    	  docTrg.Range.InsertAfter rng.Text
    	  ' Optional: insert paragraph mark after each sentence
    	  docTrg.Range.InsertParagraphAfter
    	End If
      Next rng
    End Sub

  3. #3
    Lounger
    Join Date
    Apr 2009
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='794406' date='22-Sep-2009 18:12']Does this do what you want?

    Code:
    Sub ExtractSentencesWithBy()
      Dim docSrc As Document
      Dim docTrg As Document
      Dim rng As Range
      Set docSrc = ActiveDocument
      Set docTrg = Documents.Add
      For Each rng In docSrc.Sentences
    	If InStr(rng.Text, " by ") > 0 Then
    	  docTrg.Range.InsertAfter rng.Text
    	  ' Optional: insert paragraph mark after each sentence
    	  docTrg.Range.InsertParagraphAfter
    	End If
      Next rng
    End Sub
    [/quote]







    yes!!! this is what i am searching for
    Thanks a lot for this.......
    One more thing
    can i capture all these sentenecs in to tabular format ...so that they will look more organized and a blank row along with this for the suggestive corrections.........

    Regards,
    techwriter

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    It seems more convenient to me to have a second column for comments. You can accomplish this by inserting the following line into the macro above End Sub:

    Code:
      docTrg.Range.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=2

  5. #5
    Lounger
    Join Date
    Apr 2009
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='794504' date='23-Sep-2009 11:11']It seems more convenient to me to have a second column for comments. You can accomplish this by inserting the following line into the macro above End Sub:

    Code:
      docTrg.Range.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=2
    [/quote]


    again Many Thanks for this.......
    and the idea of coloumns..
    actually i often confuse between rows and coloumns......

    Regards
    Techwriter

  6. #6
    Lounger
    Join Date
    Apr 2009
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='techwriter2k9' post='794505' date='23-Sep-2009 11:53']again Many Thanks for this.......
    and the idea of coloumns..
    actually i often confuse between rows and coloumns......

    Regards
    Techwriter[/quote]

    Hi,

    Relating to this i have one more query.
    Can we also insert a comment at those places where we have found the instances of "by"
    the word comments that are inserted using Alt+I+M.
    The format of the comment:

    Passive:
    Rationale:
    suggestions: <<this is where i place the corrective sentence>>

    Best regards,
    Techwriter

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Insert the following after the line If InStr(rng.Text, " by ") > 0 Then:

    Code:
    	  docSrc.Comments.Add rng, "Passive: " & vbCr & _
    		"Rationale: " & vbCr & "Suggestions: "
    It will add a comment for every sentence containing " by ".

  8. #8
    Lounger
    Join Date
    Apr 2009
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='794570' date='23-Sep-2009 21:08']Insert the following after the line If InStr(rng.Text, " by ") > 0 Then:

    Code:
    	  docSrc.Comments.Add rng, "Passive: " & vbCr & _
    		"Rationale: " & vbCr & "Suggestions: "
    It will add a comment for every sentence containing " by ".[/quote]


    Hi ,

    Added the same to the code,
    it's working :-)
    Thanks a lot!

    Regards,
    Techwriter

  9. #9
    Lounger
    Join Date
    Apr 2009
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='techwriter2k9' post='794571' date='23-Sep-2009 21:19']Hi ,

    Added the same to the code,
    it's working :-)
    Thanks a lot!

    Regards,
    Techwriter[/quote]


    Hi,
    This is on continuation with my previous posting , relating to ths I have one query:
    As we are finding through this code specific words in the document will it be possible that we can search using the specific style we apply to particular chunk of text in the document.
    For example:
    collecting all the text (having Heading 1 style applied on it ) from the document in to another document.
    Simlarlily for the styles that are present in user created templates style gallery.

    More Quicker response will be highly appriciated and many thanks in advance.


    regards,
    Techwriter

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I'm not sure I understand your question. If you only want to search sentences that have a particular style, you could change

    If InStr(rng.Text, " by ") > 0 Then

    to

    If InStr(rng.Text, " by ") > 0 And rng.Style = "Heading 1" Then

  11. #11
    Lounger
    Join Date
    Apr 2009
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='797817' date='14-Oct-2009 11:35']I'm not sure I understand your question. If you only want to search sentences that have a particular style, you could change

    If InStr(rng.Text, " by ") > 0 Then

    to

    If InStr(rng.Text, " by ") > 0 And rng.Style = "Heading 1" Then[/quote]


    Hi,

    Thanks for the quick response,
    My Query is to find and collect all the instances that have say for example " heading 1" style applied to text.
    that is, the styles that are available in normal.dot or the styles that are avilable in user created template (.dot).
    Also, it is required to be collected sepreately not tigether with some specific words like " be " or "by:

    For example:
    I have one document and in the document i have applied lot of styles (available in the template)
    I would like to bring out the text in another document that has " heading 1" style applied on them.
    The new document created will have all the content (in tabular format) thast has "heading 1" style applied over it.
    similar will be the case for all the other styles also.

    Regards,
    Techwriter


    Regards,
    Techwriter

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could do that without a macro:

    First, select Tools | Options, activate the Edit tab and make sure that "Keep track of formatting" is ticked. (You have to do this only once, Word remembers this setting.)

    Activate the Formatting and Styles task pane.
    Select the style you want from the dropdown list.
    Click in any paragraph with the style you want.
    Click "Select All".
    You can now copy the text and paste it into a new document.
    Attached Images Attached Images
    • File Type: png x.png (3.4 KB, 2 views)

  13. #13
    Lounger
    Join Date
    Apr 2009
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='797828' date='14-Oct-2009 12:58']You could do that without a macro:

    First, select Tools | Options, activate the Edit tab and make sure that "Keep track of formatting" is ticked. (You have to do this only once, Word remembers this setting.)

    Activate the Formatting and Styles task pane.
    Select the style you want from the dropdown list.
    Click in any paragraph with the style you want.
    Click "Select All".
    You can now copy the text and paste it into a new document.[/quote]
    Thanks Hans,
    I am able to do this easily but the text i have pasted is not arranged , it becomes one paragraph.
    I would like to arrenge this in tabular format

    Regards,
    Techwriter

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    If you use the method I described to copy all text with a specific style into a new document, each occurrence should be pasted as a separate paragraph. You can then easily convert the text to a table. I don't understand why the occurrences would run into one paragraph - that doesn't happen when I do it.

  15. #15
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='HansV' post='797837' date='14-Oct-2009 01:33']If you use the method I described to copy all text with a specific style into a new document, each occurrence should be pasted as a separate paragraph. You can then easily convert the text to a table. I don't understand why the occurrences would run into one paragraph - that doesn't happen when I do it.[/quote]
    Could the difference be linked to an option such as "Smart Copy & Paste" (Tools > Options > Edit)?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •