Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

docprop.Script macro

Hi all,

I tried below macro code for adding new script line into existed tab "Main 2" ,

but the below code works like creating another new tab "Main 2" and adding the script line as $(Include=d:\vqd eat\text\test.txt);

what to change in below code for add new script line into existed tab "Main 2"

docprop.Script = docprop.Script & chr(13) & chr(10) & "///$tab Main 2" & chr(13) & chr(10) & "$(Include=d:\vqd eat\text\test.txt);"

Thanks in advance

22 Replies
Not applicable
Author

Hi Celambarsan Adhimulam,

superb, It is working perfectly.

I really thank you a lot on sharing your knowledge and spending your valuable time with me.

Regards,

Venkat

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     One more thing i noticed in that every it adds one extra line in all the tabs did you checked that?.Will work on it and after the change post you again.

Celambarasan

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Use the code below

sub AddScript

docprop=Activedocument.GetProperties

ArrayScript = split(docprop.Script,"///$tab ")

For i=1 to Ubound(ArrayScript)

if(Left(Trim(ArrayScript(i)),Len("Main 2"))="Main 2") then

          ArrayTabScript=Split(ArrayScript(i),Chr(10))

          if(Ubound(ArrayTabScript)>=4) then

                    ArrayTabScript(4)= "$(Include=d:\vqd eat\text\test.txt);"

                    ArrayScript(i)=Join(ArrayTabScript,Chr(10))

          else

                    Dim ArrayTempScript(3)

                    For j=0 to Ubound(ArrayTabScript)

                              ArrayTempScript(j)=ArrayTabScript(j)

                    next

                    for j=Ubound(ArrayTabScript)+1 to 3

                              if(j = 3) then

                                        ArrayTempScript(j)= "$(Include=d:\vqd eat\text\test.txt);"

                              else

                                        ArrayTempScript(j)=chr(10)

                              end if

                    next

                    ArrayScript(i) = Join(ArrayTempScript,Chr(10))

          end if

          exit for

end if

next

docprop.Script = "///$tab " & ArrayScript(1)

For i=2 to Ubound(ArrayScript)

docprop.Script = RemoveLastLine(docprop.Script)

docprop.Script = docprop.Script& Chr(10)  &"///$tab " & ArrayScript(i)

next

Activedocument.SetProperties docprop

end sub

 

function RemoveLastLine (Script)

SplitArray=split(Script,Chr(10))

RemoveLastLine=SplitArray(0)

for i=1 to ubound(SplitArray)-1

          RemoveLastLine=RemoveLastLine&Chr(10)&SplitArray(i)

next

j=ubound(SplitArray)

if(len(SplitArray(j))>0) then

          RemoveLastLine=RemoveLastLine&Chr(10)&SplitArray(j)

end if

end function

Celambarasan