Note with the enable visibility option (second one) doesn't work for me. I'v tried it earlier. I get the same error.
As for the first one, I've tried implementing
Sys.Process("Winword").Window("Shell_TrayWnd").Activate();
I'm not sure what this Shell_TrayWnd is. This is the error I get after I insert the above line into my code.
Cannot obtain the window with the window class 'Shell_TrayWnd', window caption '*' and index -1. See Additional Information for details. 9:31:30 Normal
You've got a word Automation Problem.
A variable can not be accessed by Name.
You have to iterate the variables and check for the given Name to get Access to Your variable.
I have a piece of VBA code that iterates through all the variables in a document and prints them.
I use it to check if I've placed all the variables into my Word document.
Private Sub ListAllVariables() Dim myVariable As Variable For Each myVariable In ThisDocument.Variables Debug.Print myVariable.Name & " : " & myVariable.Value Next End Sub
How can I implement this in my TC function?
I know how to iterate through arrays and stuff in Javascript, but how can I iterate something I don't have access to?
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.
Thank you HKosova! Adding the ".Item()" made my function work.
Here is the final version:
function myFunc (){ var objWordApplication = Sys.OleObject("Word.Application"); objWordApplication.Documents.Open('C:\InvoiceLatTemplate.doc'); //objWordApplication.Visible = true; var WordDoc = objWordApplication.ActiveDocument; var myVariable = WordDoc.Variables.Item("Group").Name; var myVariable1 = WordDoc.Variables.Item("Group").Value; Log.Message(myVariable) Log.Message(myVariable1) }
Both name and value are logged properly.
One final question: is there a way to iterate through all the variables in a Word file? I have that function that itterates in VBA, but obviously TC script and VBA are not the same...
dasabaja wrote:One final question: is there a way to iterate through all the variables in a Word file? I have that function that itterates in VBA, but obviously TC script and VBA are not the same...
Use a for loop from 1 to Variables.Count and access the variables using Variables.Item(index):
for (var i = 1; i <= WordDoc.Variables.Count; i++) { variable = WordDoc.Variables.Item(i); Log.Message(variable.Name + ": " + variable.Value); }
Keep in mind that MS Office indexing is 1-based, not 0-based.
Worked like a charm!
I owe you a drink!
> I owe you a drink!
You may start with giving a Kudo to Helen and marking her reply as a solution 😉
Oh, I kudosed it immediately! How do I mark it as the answer?
> I kudosed it immediately
Ah, looked at another reply by Helen, my bad...
> How do I mark it as the answer?
There is an 'Accept as Solution' link in the Options menu that is on the right of the corresponding post.
User | Count |
---|---|
7 | |
5 | |
2 | |
1 | |
1 |
Subject | Author | Latest Post |
---|---|---|