How To Work With Paragraphs In Word VBA

Поділитися
Вставка
  • Опубліковано 10 січ 2025

КОМЕНТАРІ • 21

  • @drteeth11
    @drteeth11 5 років тому +1

    interesting video, thank you. looking forward to the series

  • @badbad1898
    @badbad1898 2 роки тому +1

    For the remark on 9:09, I found this explanation from the documentation at:
    learn.microsoft.com/en-us/office/vba/api/word.range.words
    "Punctuation and paragraph marks in a document are included in the Words collection."
    In another page, titled: 'Word count appears inaccurate when you use the VBA "Words" property', they have the following:
    "To return only the number of words in a document or a range, excluding paragraph marks and punctuation, use the ComputeStatistics method instead of the Words property.
    The ComputeStatistics method returns a word count that does not include paragraph marks or punctuation:
    ActiveDocument.Range.ComputeStatistics(wdStatisticWords)"
    From: support.microsoft.com/en-US/topic/word-count-appears-inaccurate-when-you-use-the-vba-words-property-835c0cd8-3bff-50d0-b6ea-9da4ca22e3ff
    Thank you for your effort on vba Word. There are not too much tutorials covering it.

  • @stanislavdimitrov1643
    @stanislavdimitrov1643 2 роки тому

    Great video. I learned very much from it. I am happy 😊🙂

  • @wayarberry
    @wayarberry 4 роки тому +1

    Very clear and informative, thank you! I would like to have code which looks at the first paragraph after an H1 header (in my case, a chapter name in a book), go to the first paragraph of the chapter, highlight the first three words, and set them to small caps. This is a flourish added by some book interior formatters.

  • @PedroFerreira-qw1kz
    @PedroFerreira-qw1kz 4 роки тому

    Very Good! Thank you ! I've improved a lot!

  • @michalroesler
    @michalroesler 5 років тому +3

    That's very good and informative video and I've learnt a lot from it. What I 'm looking for is to find a unique string in some paragraph located in the middle of a large document and then move to the next or to the third paragraph, counting from the string that has been found. Either way, Thumbs up and subscribe for this video.

    • @SigmaCoding
      @SigmaCoding  5 років тому +1

      This sounds like an interesting topic, so you got added to the list of topics to be covered. In essence, what you could do is use the Found Object and see if a match occurred. If it did then you have a new range object that you can use to navigate.

  • @guruduttkamathproact
    @guruduttkamathproact 4 роки тому +1

    Awesome video. Thanks. Is there a way to say do this for the current paragraph?

    • @SigmaCoding
      @SigmaCoding  4 роки тому +2

      There are a couple of ways to do this, but let's just assume we are talking about the paragraph that we currently have our cursor in. Anytime I talk about the cursor I'm really talking about the "Selection" object, so if I have a my cursor in my paragraph I can write the following:
      Sub GrabCurrentPara()
      'Declare our Variables.
      Dim WrdPara As Paragraph
      Dim WrdSelec As Selection
      'Grab the current Selection
      Set WrdSelec = Application.Selection
      'Grab the Paragraph
      Set WrdPara = WrdSelec.Paragraphs(1)
      'Select it.
      WrdPara.Range.Select
      'Make it all Bold
      WrdPara.Range.Bold = True
      End Sub
      Hopefully, that helps you out. :)

  • @JohnnyDowntheTubes
    @JohnnyDowntheTubes 3 роки тому +1

    can you do a file dialog on vba FOR Word and cycle through the selected files to process mulitiple docuements. I'm finding it very hard to find examples of this.

  • @gajendrashettigar277
    @gajendrashettigar277 5 років тому +2

    Hi......If there are multiple paragraph and you wish to select a particular paragraph how would you do it...Please make a video of this and shar

    • @SigmaCoding
      @SigmaCoding  5 років тому +1

      If you want to select a specific paragraph you can just select by passing through the index. It would look like the following:
      Set Paragraph1 = ActiveDocument.Paragraphs(1)

  • @femaledeer
    @femaledeer 5 років тому +2

    Would have been interesting if there is a way to insert an object before or after a paragraph.

    • @SigmaCoding
      @SigmaCoding  5 років тому +1

      I go into the topic of positioning objects in this video (ua-cam.com/video/tlLDbk5Saao/v-deo.html), it is where we take Excel objects and paste them in a Word document.

  • @luperobles4474
    @luperobles4474 4 роки тому

    GRACIAS MUY BUENO!!!

  • @ignacioa3698
    @ignacioa3698 5 років тому

    Now question- Unlike the other videos, in this video you don’t have neither the ‘Word.Application’ nor the ‘Word.Document’ object variables defined which I was expecting to see at the outset?
    Is that because in this scenario you don’t need to define those two as separate variables since you have the Word document and the Word application previously open already and you’re just working at the paragraph object level? So you’re really not opening a new instance of the application or a new document page, correct so those variable types need not be listed?

    • @SigmaCoding
      @SigmaCoding  5 років тому +1

      So the reason I don't define the the ‘Word.Application’ or ‘Word.Document’ object is because now I am working from within the Word application itself. Now technically I could, but it really doesn't make sense to in this scenario. I would compare this to working in the Excel application, I don't take the time to define the application because it is assumed when I reference the application we are talking about the host application.

  • @francesoutlaw7021
    @francesoutlaw7021 Рік тому

    Excellent! I was hoping you'd cover how to hide and unhide paragraph(s) using a checkbox. Let's say I have three paragraphs and I'd like to hide paragraphs 1 and 3, leaving paragraph 2 showing. May I ask you for the script? Your reply with the script is ok rather than making a full video. Thanks!

  • @victormiguel8972
    @victormiguel8972 4 роки тому

    Man, how I put topics(points) in the word using the VBA?

  • @mudasserahmed829
    @mudasserahmed829 4 роки тому

    How can we number paragraphs?

    • @SigmaCoding
      @SigmaCoding  4 роки тому

      You don't need to, if you use the paragraphs collection in the document you can throw that in a for loop and just increment a number.