cancel
Showing results for 
Search instead for 
Did you mean: 

Converting VBA Code to VB to Use in Code Stage

SeanScudellari
Level 4
Hello, I have some VBA code I wrote to get all bullet point text in a Word document and I would like to use this within a code stage in Blue Prism to get all bullet point text within a text variable or preferably, a collection variable. The VBA code runs fine within Word, but I'm having trouble converting the code into VB to work within Blue Prism. 

Here is  the VBA code:

Dim Para As Paragraph
For Each Para In ActiveDocument.Paragraphs
       If Para.Range.ListFormat.ListType = wdListBullet Then
       MsgBox Para.Range
End If
Next Para


The main issue I seem to be running across is "paragraph" is not a valid data type in Blue Prism that can be stored in a text or collection variable. So I'm a bit stuck on how to handle this. Also, I know that "wdListBullet" corresponds to a value of 2 for its enumeration, so I believe the value 2 needs to be used instead of "wdListBullet" within the code stage. Any help would be greatly appreciated. 

Thank you!


------------------------------
Sean Scudellari
------------------------------
13 REPLIES 13

Hey @Michael ONeil. This is very helpful. Thank you so much for pointing this out!​

------------------------------
Sean Scudellari
------------------------------

@PabloSarabia Please see my reply above. Thanks!​

------------------------------
Sean Scudellari
------------------------------

Hi @Sean Scudellari

Sorry, didn't see the message 🙂

First, in your code stage add two input parameters, "strStartText" and "strEndText". (You need to indicate here the start text that you want to find to start checking for bullet texts, and the end text to stop checking) 

Also you need to add a output parameter as collection, in my example "dtResult"

Dim doc as Object = GetDocument(handle,documentname)
Dim range As Object

Dim Para As Microsoft.Office.Interop.Word.Paragraph​

Dim table As New DataTable
table.Columns.Add("Bullets", GetType(String))

Dim blnStart as Boolean 
blnStart = false

For Each Para In ActiveDocument.Paragraphs

  If Para.Range.Text.Contains(strStartText) Then
    blnStart = true
  End If

  If Para.Range.ListFormat.ListType = wdListBullet and blnStart Then
    table.Rows.Add(Para.Range.Text)


  If Para.Range.Text.Contains(strEndText) Then
    exit for 
  End If

  
Next Para

dtResult = table


Try with this!

Hope this helps you! And if this solves the problem, remember mark as the best answer

See you in the Community, bye 🙂

------------------------------
Pablo Sarabia
Solution Manager & Architect
Altamira Assets Management
Madrid
------------------------------

Hey @PabloSarabia No worries! I don't think I tagged you properly in my previous reply.

I was able to get your code working after tweaking it a little bit. I really appreciate the help!

The final thing I need help with is starting the search for the headers on the second page of the document. I realized that the first page of the document has a table of contents that lists the same Section 1 and Section 2 header names. I need to have the code stage start searching for the bullets on page 2 of the document instead of page 1 so that it skips the table of contents. Please let me know if you know a solution.

Thank you again!​​​

------------------------------
Sean Scudellari
------------------------------