How to efficiently loop through paragraphs and make simple changes with Word VBA

This is regarding my answer with SO post How to remove paragraph marks with different format in MS-Word. My primary question, is there any way performance of the code could be improved to operate on document as intended by OP (2.2 MB and has 2.1K pages, 871K words, 4,6M characters including spaces)?
On Secondary, is there a simple way or workaround that I am missing (and making things unnecessary complicated) to perform the sane task efficiently?

Here I reproduce my code after adding some futile measures to improve performance of the code with file of the size specified by the OP.

    Option Explicit     Sub ReplacePara()     Dim Para As Paragraph, Xstr As String, Rng As Range     Dim i As Long, ln As Long, tm As Double, PrCnt As Long     Dim PrvChrSize As Integer, NextChrSize  As Integer     Dim PrvChrFont As String, NextChrFont  As String     Dim PrvChrItalic As Boolean, NextChrItalic As Boolean     tm = Timer  ‘Following measures added to improve performance ‘but on the contrary it’s found instead of increasing time taken     Application.ScreenUpdating = False         With Options         .Pagination = False         .CheckSpellingAsYouType = False         .CheckGrammarAsYouType = False         End With           With ActiveDocument         PrCnt = .Paragraphs.Count         Debug.Print PrCnt         For i = .Paragraphs.Count To 1 Step -1         Set Para = .Paragraphs(i)         ln = Para.Range.Characters.Count              If ln > 1 Then                 With Para.Range.Characters(ln - 1).Font                 PrvChrSize = .Size                 PrvChrFont = .Name                 PrvChrItalic = .Italic                 End With                  If i < .Paragraphs.Count Then                     With .Paragraphs(i + 1).Range.Characters(1).Font                     NextChrSize = .Size                     NextChrFont = .Name                     NextChrItalic = .Italic                     End With                 Else                 NextChrSize = 0                 NextChrFont = ""                 NextChrItalic = False                 End If             End If              'Debug.Print i, PrvChrSize, PrvChrFont, NextChrSize, NextChrFont             If (PrvChrSize = 15 And (PrvChrFont = "Arial" Or PrvChrItalic = True)) _             And (NextChrSize = 15 And (NextChrFont = "Arial" Or NextChrItalic)) Then             Para.Range.Characters(ln).Text = " "             End If         .UndoClear         'If PrCnt < 1000 Then Debug.Print i & "/" & PrCnt         Next       End With          With Options         .Pagination = True         .CheckSpellingAsYouType = True         .CheckGrammarAsYouType = True         End With     Application.ScreenUpdating = True     Debug.Print " Seconds taken:" & Timer - tm     End Sub 

The added measures actually found to increase time taken (from 3 odd minutes to 4 odd minutes) with documents of 124 pages. I haven’t ventured far to go for LockWindowUpdate API.

Though the code tested Ok with documents of 100 pages around. I could not finish the task with a makeshift giant file of around 2.4 K pages. It is virtually crashing Word (not recovering from ‘Not responding mode’). I ceated the file with a simple code stub with the sample file linked by OP in the SO post. Code stub was also produced for ease is testing.

Sub makebig() Dim Rng As Range, MyRange As Range Dim Wd As Document Dim i  As Long Set Wd = ThisDocument Set Rng = Wd.Content Rng.Copy      For x = 1 To 2000     Set MyRange = Wd.Content     MyRange.EndOf Unit:=wdStory, Extend:=wdMove     MyRange.Paste     Next End Sub 

Running the code with sample file twice (1st time with For x = 1 To 2000 and second time with For x = 1 To 1) will produce a file about 2.4 K pages. For getting a file of 124 pages from the sample file 200 loops are sufficient.

How do I access paragraphs with the JSON API?

With the JSON API module, I am trying to access paragraphs. In the JSON object is does not allow me to access the nested paragraphs.

How would I go about accessing the paragraphs with the JSON API?

*****Update with Solution*****

  1. In the api call you need to have the correct URL format: /jsonapi/{entity_type_id}/{bundle_id}[/{entity_id}]?_format=api_json. The key here is to add this at the end of your the URL for the api call: ?include={name of paragraph}. For example: /jsonapi/node/page?_format=api_json&include=field_testing_json_api

  2. Once you have the correct API call, you need to go to the Drupal admin dashboard and go to people/permissions and under the Paragraphs Type Permissions section you need to grant access to view content to the specific paragraph you want the user to access.

Front page per language (paragraphs)

I have a multilingual site in Drupal 8 that needs to have a different node for front page on each language. The node alias is homepage and it needs to look clean.


Entering each URL will lead you to a different node. Can’t use content translation as most of the page is using paragraph types. Right now, entering either one will lead you to the original front page (in english). Thanks.

Edit: I’m using mostly content blades and hero slides in the website, the duplicate question didn’t help to answer.

Migrate node with paragraphs from Drupal 7 to Drupal 8

I’m trying to figure out how migrating content from a Drupal 7 site to a Drupal 8 site works. I managed to understand how to create a custom module to migrate nodes with regular fields to my new D8 site.

But I also have one content type where I use paragraphs. And I can’t seem to find a well documented example on how to do this. I found some examples but they all seem to use different methods. This one seems like the most up to date. But how to make the code from #9 work?

field_paragraphs: plugin: sub_process source: field_source_paragraphs process:   target_id:     -       plugin: migration_lookup       migration:         - paragraph_box         - paragraph_grid         - paragraph_text_embedded       source: value     -       plugin: extract       index:         - 0   target_revision_id:     -       plugin: migration_lookup       migration:         - paragraph_box         - paragraph_grid         - paragraph_text_embedded       source: value     -       plugin: extract       index:         - 0 

So the field_paragraphs and field_source_paragraphs I understand. But what are these paragraph_ items under migration? Is this where I set the paragraph bundles? And if not where do I set the paragraph bundles and there fields? So where do I begin? What are the right steps to take?

Thanks in advance

I need to alter Paragraphs field, but only text_format field type getting alter, Other field not getting alter

I need to alter Paragraphs field, but only text_format field type getting alter, Other field not getting alter in drupal 8

function mymodoule_field_widget_entity_reference_paragraphs_form_alter(&$  element, &$  form_state, $  context) {   if ($  element['#paragraph_type'] == 'text_and_counter_block') {     //echo '<pre>'; var_dump($  context);     //print_r($  element['paragraph__field_background_style']); exit();     $  element['subform']['field_two_column_title']['widget'][0]['#title'] = 'Altered title';     $  element['subform']['field_two_column_style']['widget'][0]['#title'] = 'Altered title';    } } 

loop through paragraphs ID’s in node template

In a custom twig template for content type “legal”, I’m trying to loop through a 3-field paragraph called “legal_section.” It’s referenced by my content type, using an entity reference field called “field_legal_section” – set to allow unlimited entries. For each, I want to print the paragraph id. I’m not quite sure how, in this scenario. Maybe there’s a little more involved than I thought?

I’m currently trying something like this, in the twig template:

{% if content.field_legal_section %}  {% for item in content.field_legal_section %}   id: {{ }}<br/>   show the 3 fields: {{ content.field_legal_section }}  {% endfor %} {% endif %} 

If relevant, the individual fields within the paragraph called legal_section are:

 field_legal_section_title  field_legal_section_subtitle  field_legal_section_body 

Conditional Fields inside Paragraphs not working

Am able to get the configured conditional fields in hook_field_widget_WIDGET_TYPE_form_alter() and trying to apply them for Paragraph fields but not working, below is the code(most of it copied from Conditional Fields module file):

$ dependencies = conditional_fields_load_dependencies(‘paragraph’, ‘paragraph_machine_name’);

if (!empty($ dependencies)) {

    foreach ($  element['subform'] as $  field_name => $  field_details) {       if (isset($  dependencies['dependents'][$  field_name])) {          foreach ($  dependencies['dependents'][$  field_name] as $  id => $  dependency) {           if (!isset($  element['subform']['#conditional_fields'][$  field_name]['dependees'][$  id])) {             conditional_fields_attach_dependency($  element['subform'], ['#field_name' => $  dependency['dependee']], $  field_details, $  dependency['options'], $  id);           }         }       }        if (isset($  dependencies['dependees'][$  field_name])) {         foreach ($  dependencies['dependees'][$  field_name] as $  id => $  dependency) {           if (!isset($  element['subform']['#conditional_fields'][$  field_name]['dependents'][$  id])) {             conditional_fields_attach_dependency($  element['subform'], $  field_details, ['#field_name' => $  dependency['dependent']], $  dependency['options'], $  id);           }         }       }     }   } 

Can someone please help me in it?