Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
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
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Check it out

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

          'ArrayScript(i)="Main 2" & chr(10) & "Set vVar=2;Set vVar1=3;"

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

          if(Ubound(ArrayTabScript)>=4) then

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

          else

                    for j=Ubound(ArrayTabScript) to 4

                              if(j=4) then

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

                              else

                                        ArrayTabScript(j)=chr(10)

                              end if

                    next

          end if

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

          exit for

end if

next

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

For i=2 to Ubound(ArrayScript)

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

next

Activedocument.SetProperties docprop

end sub

Celambarasan

Not applicable
Author

Hi sorry for late reply,

i tried your code but

it is generating an error Subscript out of range : "j"

what to change in code ?

Thanks in advance.

error.JPG

Not applicable
Author

Celambarasan Adhimulam,

Excellent job. But i've one doubt why it is not inserting the script in 3rd tab. According to the below it should insert in 3rd tab also b'coz the loop is repeating for the second time also.

For i=2 to Ubound(ArrayScript)

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

next

perumal_41
Partner - Specialist II
Partner - Specialist II

Hi,

this macro not create new line . Main 2 Tab need 4 th Row empty or Data .so u first create 10 row in Main 2 Tab

.afetr run this macro working perfectly

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi jacq

     I restricted it here

    

For i=1 to Ubound(ArrayScript)

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

          ArrayScript(i)="Main 2" & chr(10) & "$(Include=d:\vqd eat\text\test.txt);"

end if

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi

     Most probably it will work check it

    

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

          'ArrayScript(i)="Main 2" & chr(10) & "Set vVar=2;Set vVar1=3;"

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

          if(Ubound(ArrayTabScript)>=4) then

                    ArrayTabScript(4)="hi how r u?"

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

          else

                    Dim ArrayTempScript(4)

                    For j=0 to Ubound(ArrayTabScript)

                              ArrayTempScript(j)=Array(ArrayTabScript(j))

                    next

                    msgbox Ubound(ArrayTempScript)&isArray(ArrayTempScript)&Ubound(ArrayTabScript)

                    for j=Ubound(ArrayTabScript)+1 to 4

                              msgbox Ubound(ArrayTempScript)

                              if(j=4) then

                                        ArrayTempScript(j)="hi how r u?"

                              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 = docprop.Script & chr(10)&"///$tab " & ArrayScript(i)

next

Activedocument.SetProperties docprop

end sub

Celambarasan

Not applicable
Author

Hi,

sorry to interupt you again.

I tried your code but it is giving an error "Type Mismatch".

Please check the below error image.

Thanks in advance.

12.png

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     I hope everything got fixed in this

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

          'ArrayScript(i)="Main 2" & chr(10) & "Set vVar=2;Set vVar1=3;"

          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 = docprop.Script &"///$tab " & ArrayScript(i)

next

Activedocument.SetProperties docprop

end sub

Celambarasan

Not applicable
Author

Hi ,

sorry for late.

No it is removing the "Main 3" tab and placing the "Main 3" script lines in "Main 2" tab.

Please can you suggest what to do now .

Thanks in advance.

removing Main 3.JPG

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi

     Change this part

    

For i=2 to Ubound(ArrayScript)

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

next

to

For i=2 to Ubound(ArrayScript)

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

next

Celambarasan