iMacros concatenating strings from datasource - datasource

In the below iMacros how can I set a variable value and then concatenate it?
VERSION BUILD=8530828 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
SET !DATASOURCE allsource.CSV
SET !TIMEOUT 1
SET !VAR! = My<SP>Content<SP>Here.
TAG POS=1 TYPE=TEXTAREA FORM=ID:pst-main ATTR=ID:description CONTENT={{!COL1}}
How can the SET !VAR1 = MyContentHere. work? Please correct my syntax.
And, how can I concatenate COL1 and VAR1 the below way didn't work
TAG POS=1 TYPE=TEXTAREA FORM=ID:pst-main ATTR=ID:description CONTENT={{!COL1}} !VAR1
Please correct my syntax, thanks
EDIT1
Also, I am able to set Loop start as SET !LOOP 2 how can I set LOOP end without manually setting Loop Number and hit play loop button?

To assign a value to a variable, use this:
SET !VAR1 My<SP>Content
Concatenate COL1 and VAR1:
TAG POS=1 TYPE=TEXTAREA FORM=ID:pst-main ATTR=ID:description CONTENT={{!COL1}}{{!VAR1}}
If you don't want to set loop end manually, you'll need to use JavaScripting.
Your macro should look like this:
VERSION BUILD=8530828 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
SET !DATASOURCE allsource.CSV
SET !TIMEOUT 1
SET !VAR1 My<SP>Content<SP>Here.
TAG POS=1 TYPE=TEXTAREA FORM=ID:pst-main ATTR=ID:description CONTENT={{!COL1}}{{!VAR1}}
Read here about JavaScripting, you will have to save this code in a *.js file.
var macro = "CODE:SET !ERRORIGNORE YES\n";
macro =+ "SET !DATASOURCE allsource.CSV\n";
macro =+ "SET !DATASOURCE_LINE {{loop}}\n";
macro =+ "SET !TIMEOUT 1\n";
macro =+ "SET !VAR1 My<SP>Content<SP>Here.\n";
macro =+ "TAG POS=1 TYPE=TEXTAREA FORM=ID:pst-main ATTR=ID:description CONTENT={{!COL1}}{{!VAR1}}\n";
for(var i=1;i<=20;i++)
{
iimDisplay(i);
iimSet("loop", i);
iimPlay(macro);
}

Related

Insert text before figure caption

I want to insert some text before the 'Figure' label when inserting a caption. i.e. turn this:
1.1.1 <Figure caption text>
into this:
<some text> 1.1.1 <Figure caption text>
I am using the InsertCaption method of the range object:
rng.Text = "asf"
rng.InsertCaption(Word.WdCaptionLabelID.wdCaptionFigure, ": " & caption,, Word.WdCaptionPosition.wdCaptionPositionBelow)
rng.InsertAfter(Chr(13) & Chr(10))
I cannot seem to modify the range object to include the text at the start, it always seems to enter the caption on its own line.

Inserting Hyperlink into Content Control in Word - Have tried several ways but no success

Can anyone help on this please.
I have a word userform that populates a letter. Depending on the optionbutton pressed I want to insert a hyperlink that I have typed into the Macro VBA editor. I can get it to work by using the line below but the link is not clickable. I have tried playing about with the HYPERLINKS.ADD function without success. So My questions is, if my content control is called "Link" (also the TAG) how do I add text and make it a clickable hyperlink all in one?
Set CClist = ActiveDocument.SelectContentControlsByTitle("Link")
For Each cc In CClist
cc.Range.Text = "MY LINK"
Next cc
I have tried:
Set CClist = ActiveDocument.SelectContentControlsByTitle("date")
For Each cc In CClist
cc.Range.hyperlinks.add range ("my link")
Next cc
Damian
Try something along the lines of:
With ActiveDocument
.Hyperlinks.Add Anchor:=.SelectContentControlsByTitle("Link")(1).Range, _
Address:="Hyperlink Address", SubAddress:="", ScreenTip:="Some Tip", _
TextToDisplay:="Display Text", Target:=""
End With
For further details, see: https://learn.microsoft.com/en-us/office/vba/api/word.hyperlinks.add

How to select a value from a DropDownList in a Word Macro using VBA?

I am creating a macro using both vbscript and vba, this macro is being called by the script code and works well but when I try to select a value outside the macro itself, I keep getting an error about the way im trying to set the value.
I have named the dropdownlist as "Result" and when I try to set the value it does not work, I also tried with the default name "DropDownList" , but none of those options seems to work, maybe i am missing object references.
I already declared the objects that I need
Set objWord = CreateObject("Word.Application")
Set activeDoc= objWord.ActiveDocument
activeDoc.FormFields("Result").DropDown.Value = 2
The error i am getting right now is that "The Requested memeber of the coleection does not exist."
The only solution I can come up with is to set the value when I'm creating the dropdown in the macro:
ActiveDocument.Tables(1).Cell(Row: = 4, Column: = 4).Select
Set objCC =
Selection.Range.ContentControls.Add(wdContentControlDropDownList)
With objCC
.Title = "Result"
.Tag = "Result"
.DropdownListEntries.Add("Passed", "Passed").Select
End with
I got everything messed up, but in the end I realized what was my mistake. I wasn't using the tag so the Item was loose, I had to use the index of the correct content control
Set objCc = activeDoc.ContentControls.Item(5)
Set objLe1 = objCc.DropdownListEntries.Item(1)
objLe1.Select
Thanks very much for your part of code, I have so much trouble to find how to do this !
I add just :
With ThisDocument.tables(blabla).Cell(x,y)
Set objCc = .Range.ContentControls.Item(1)
Set objLe1 = objCc.DropdownListEntries.Item(2)
objLe1.Select
End With
And it works perfectly within my project ! Ty again, see you !

Setting Title of Chart automatically

Is there anyway to have the title of a chart be equal to string variable. I recorded me manually changing the title and it came up as first activating it, then showing my text edit, but how do I do this if I don't want to activate it. I know the name of the chart is chart 1, so was trying to find a way to have the title of chart 1 be set to my string variable (which I generate from another loop elsewhere). Thx
activesheet.chartobjects("chart 1").activate
activesheet.charttitle.text="my text edit"
ActiveSheet.ChartObjects("Chart 1").Chart.ChartTitle.Text = "my text edit"
You can read more about chartObjects here
I prefer this solution:
Dim var As String
Set objChrt1 = Sheets("sheet1").ChartObjects(1)
Set myChart1 = objChrt1.chart
myChart1.ChartTitle.Text = "my text edit"
var = myChart1.ChartTitle.Text
MsgBox var

How to change header of word file by Drop-down list

I would like to change title of my header based on a drop down by using macro help.
I am trying to find all the items in my word file by below code but it seems that the text box in my header is not coming in ActiveDocument.ContentControls list. would you mind help me to solve my problem.
My "test" message never appear.
For Each oCC In ActiveDocument.ContentControls
If oCC.Tag = "CB_DOC_TYP" Then
MsgBox "doc Type"
For Each oDD In ActiveDocument.ContentControls
If oDD.Tag = "TB_Header_Titel" Then
oDD.SetPlaceholderText , , oCC.Title
MsgBox "test"
End If
Next oDD
End If
End If
Header is different part of the document. When calling ActiveDocument.ContentControl you search by default in wdMainTextStory section. To get your content control which is in header try one of the references:
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).ContentControls
or
ActiveDocument.StoryRanges(wdEvenPagesHeaderStory).ContentControls
or
ActiveDocument.StoryRanges(wdFirstPageHeaderStory).ContentControls
You can also loop through all document story ranges in this way:
Dim SR As Object
For Each SR In ActiveDocument.StoryRanges
'your macro here
'....
Next