From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

activex

Solved!
Go to solution

Hi

 

I been stuck trying to convert this VBA code into Labview Activex.

 

The VB code selects a range between two bookmarks in the document. Then the VB code then select the text that is between the ranges and returns a text box. Evently, I want to put that text into a Labview variable. But I can't seem to get this basic code to work using activeX.

Here is the VB code:

 

Sub Retrieve()

Dim ttext As String

Dim oRng As Range

Set oRng = ActiveDocument.Range

oRng.Start = ActiveDocument.Bookmarks("row1col4").Range.End

oRng.End = ActiveDocument.Bookmarks("row1col5").Range.Start

oRng.Select

ActiveDocument.Bookmarks.Add "oRng", oRng

ttext = ActiveDocument.Bookmarks("oRng").Range.Text

MsgBox ActiveDocument.Bookmarks("oRng").Range.Text

End Sub

 

The VB code works fine, I just can't find a correct way yo convert this to activeX.

 

 

 

  

0 Kudos
Message 1 of 11
(3,543 Views)

There is surely a way to do it with the ActiveX methods and properties but since you have working VB code you can use ActiveX to run it. You may have to change the document security to trust access to vb code.

 

Ben64

0 Kudos
Message 2 of 11
(3,540 Views)

I wanted to keep it in Labview, to convert the text (out of the VB code) into a labview variable easily, plus I have to loop the code multiple times to get all the data out of the WORD document.

I thought I try the code you sent, but it was for Excel, I need it for Word 2003. I tried converting it to Word._application, but it didn't like it.

0 Kudos
Message 3 of 11
(3,525 Views)

Look in the Help --> Examples --> Communication with External Applications --> Word

0 Kudos
Message 4 of 11
(3,516 Views)

Adapted to Word.

 

Ben64

0 Kudos
Message 5 of 11
(3,514 Views)

Ok, I did get the macro to run. Thank you..

Now, how can I get that "text from the msgbox" out of the VBA code and into a Labview variable?

That's why I was trying to keep all the code with Labview ActiveX....

 

The problem with all the example is they write data to a word document. I'm trying to pull data out of the word documentand that was my problem converting the VBA code to a workable activeX.

 

0 Kudos
Message 6 of 11
(3,505 Views)

This snippet is pretty much a direct translation of the VB code into LabVIEW using ActiveX nodes:

WordBookmarksActiveX.png

EDIT: by the way, in case you're unfamiliar with snippets: you can drag this image directly to the block diagram of a LabVIEW VI (for some web browsers, you may need to drag it to the desktop first, and from there into the block diagram).  I can save it for an earlier version of LabVIEW if necessary.

0 Kudos
Message 7 of 11
(3,504 Views)

That snippet was exactly what I was looking for Thank You, but...it doesn't work.

 

The text data is not coming out on the message box(it's empty).

When I set stops in the Labview ActiveX code you just sent and watch the word document (I added code to open the word document) the text range doesn't highlight between the specific bookmarks, like when I step through the VBA code.

I think there is something wrong with the range select invoke node.

0 Kudos
Message 8 of 11
(3,498 Views)

Hey, I didn't say I'd tested it!  (If you upload your Word document I can give it a try).

 

If you run the LabVIEW code with Execution Highlighting turned on, do you see an error from any of the ActiveX nodes?

0 Kudos
Message 9 of 11
(3,490 Views)
Solution
Accepted by topic author DL_LEO

Found the error - sorry, I didn't copy the VB code carefully enough and I left out a few nodes.  This one works (I tested it).  I don't see the selection get highlighted, but the message box contains the correct text.

WordMessageBoxText.png

EDIT: oops, still one minor error - your VB code uses the Start for one bookmark and End for the other, I used End for both.  If you want an exact match, just change the property from End to Start for the appropriate bookmark.

Message 10 of 11
(3,487 Views)