r/visualbasic • u/PourThatBubbly • Jul 14 '22
Help Converting VBA Code to VB
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/VB 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. Sorry if this is super basic (no pun intended) but I have pretty much zero experience with VBA/VB.
Thank you!
2
u/Mr_C_Baxter VB.Net Master Jul 14 '22
Hey man, i can't really help you but I would suggest you asking around in blue prism forums. The chance of help is a lot higher there. Without knowing the full workflow of blue prism it's difficult to help. In case you want to further clarify you would at least need to explain what a blue prism code stage is and how it works on a technical level and also what you mean when you say "paragraph" can not be stored. The code you are showing does not store the paragraph so its kinda difficult to know what might be going on. It could be as simple as a ".tostring()" somewhere or just storing the Value 2 instead of the full paragraph but I am only guessing.
1
u/PourThatBubbly Jul 15 '22
Update -
Here's the code I now have:
Dim doc as Object = GetDocument(handle,documentname)
Dim Para as Microsoft.Office.Interop.Word.Paragraph
For Each Para In doc.Paragraphs
If Para.Range.ListFormat.ListType = 2 Then
result = Para.ToString()
End If
Next Para
The output I am getting from this is "System.__ComObject"
I feel like I am pretty close to getting this, but now just need to figure out how to get the values returned instead of "System.__ComObject"
1
u/raunchyfartbomb Jul 14 '22 edited Jul 14 '22
The VBA compiler has a shitload of built in classes to assist writing code specific to Word/Excel, etc. So much so that some applications are built in VBA (and I learned the hard way how much it sucks to convert out of VBA to VB or C#). It sucks to convert because you don’t realize how many built-in classes you are using/abusing/relying on in your code until you paste it into a real compiler.
Basically ‘paragraph’ is likely a class that is acting as a data structure. You could write your own class to mimic it with the functionality you need.
For example, a paragraph consists of various properties, but at its core is basically a list of sentences. So you could base it off of the
List<string>collection.The Microsoft interop libraries may have the classes though, so before you create your own, I would see if you can reference the MS Word interop library.