09-28-2012 10:26 AM
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.
Solved! Go to Solution.
09-28-2012 10:46 AM
09-28-2012 01:08 PM
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.
09-28-2012 01:57 PM
Look in the Help --> Examples --> Communication with External Applications --> Word
09-28-2012 02:01 PM
09-28-2012 04:04 PM
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.
09-28-2012 04:05 PM - edited 09-28-2012 04:08 PM
This snippet is pretty much a direct translation of the VB code into LabVIEW using ActiveX nodes:
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.
09-28-2012 04:30 PM
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.
09-28-2012 04:42 PM
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?
09-28-2012 04:56 PM - edited 09-28-2012 04:59 PM
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.
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.