Solved! Go to Solution.
dasabaja wrote:After implementing the line that opens the document I got a different error.
TypeError WordDoc.Variables is not a function Error location: Unit: "HR\HR SmartTemplates\Script\Unit1" Line: 8 Column: 26.Any hints on what this might be?
Change Variables("Group") to Variables.Item("Group"). The former is VBA/VBScript syntax, but in other languages you need to use the .Item() method to access collection items in MS Office COM objects.
Hi Lane,
I recommend that you perform your validations via COM. All MS Office applications provide very convenient and deep access to their documents this way, so you should be able to check anything you want. To obtain a COM object, use the Sys.OleObject property (for example, to obtain MS Word, use word = Sys.OleObject("Word.Application")).
To find out which objects, properties and methods you should use to work with the Microsoft Word application, see the http://msdn.microsoft.com/en-us/library/aa221371(v=office.11).aspx MSDN article.
Hi Lane,
Try using the following code instead:
Set objWordApplication = Sys.OleObject("Word.Application")
Set objActiveWindow = objWordApplication.ActiveWindow
objActiveWindow.Selection.GoTo What, , , "\para"
The fact is that VBA doesn't require certain order of the parameters. You can specify parameters in any order using the Param_Name := "Param_Value" syntax. However, VBScript requires that all the parameters be specified in the order declared in the method's description. If you need to omit some parameters, you can just specify spaces for them and delimit the parameters using commas.
I hope this information helps 🙂
Hi all.
Sorry for bringing this topic from the dead, but I'm having kinda the same problems like the original poster.
There's an awesome answer on how to manipulate document content, but what I'm interested in is reading variables from a .doc file added using VBA.
I have a function that adds variables to a Word file
Private Sub AddVariable() ThisDocument.Variables.Add "Group", "Group" End Sub
So, I have a variable named Group that has a value Group. It's stupid, I know, but just as an example.
I would like to use TC and read the value of the variable Group. The document is open at the same time as TC, it's in windows' processes.
From what I read here (and oh similar topics), this is the function I've come up with in TC.
function myFunc (){ var objWordApplication = Sys.OleObject("Word.Application"); objWordApplication.Visible = true; var WordDoc= objWordApplication.ActiveDocument; var myVariable = WordDoc.Variables("Group").Value; Log.Message(myVariable) }
This doesn't work. When I type „WordDoc.“ , there is no intellisense after the dot. As if there is no Variables property.
Also, the error i get is:
JavaScript runtime error
Cannot read property 'Variables' of undefined.
So, I'm kinda stuck.
I could really use some help!
The error you're getting means that the WordDoc variable is not getting anything. Not sure why the ActiveDocument call is not working.
Try the following instead. Make sure that Word is closed and not running and do the following:
function myFunc (){ var objWordApplication = Sys.OleObject("Word.Application"); objWordApplication.Documents.Open(myDocumentPath); var WordDoc= objWordApplication.ActiveDocument; var myVariable = WordDoc.Variables("Group").Value; Log.Message(myVariable) }
Replace the bold with the actual file path and name of the document. See if that works.
Hi, tristaanogre.
Sorry for the late reply, I wasn't in my office during the weekend.
After implementing the line that opens the document I got a different error.
TypeError WordDoc.Variables is not a function Error location: Unit: "HR\HR SmartTemplates\Script\Unit1" Line: 8 Column: 26.
Any hints on what this might be?
Hi,
At the first glance your code seems to be correct... The only idea that I have at the moment is related to the specifics of Office applications described in the "Note for Microsoft Office users" section of the https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/sys/oleobject-propert... topic. Does it help?
User | Count |
---|---|
7 | |
5 | |
2 | |
1 | |
1 |
Subject | Author | Latest Post |
---|---|---|