22 Replies Latest reply: Mar 29, 2012 5:51 AM by Celambarasan Adhimulam RSS

    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

        • Re: docprop.Script macro

          Hi all,

           

          Waiting for response.

           

          Any suggestion will appreciates greatly on this.

           

          Thanks in advance.

            • Re: docprop.Script macro
              Celambarasan Adhimulam

              Hi

                   Check with this

              sub AddScript

              docprop=Activedocument.GetProperties

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

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

              docprop.Script = Join(ArrayScript,chr(10))

              msgbox docprop.Script

              Activedocument.SetProperties docprop

              end sub

               

              Hope it helps

              Celambarasan

                • Re: docprop.Script macro

                  Hi,

                   

                  It is not adding the script line in "Main 2" tab , it is going to the last tab and adding the script line there.

                   

                  How to add script line in only "Main 2" tab.

                   

                  Thanks in advance.

                    • Re: docprop.Script macro
                      Celambarasan Adhimulam

                      Hi

                           Check with this

                       

                      sub AddScript

                      docprop=Activedocument.GetProperties

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

                      For i=0 to Ubound(ArrayScript)

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

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

                       

                      end if

                      next

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

                      Activedocument.SetProperties docprop

                      end sub

                        • Re: docprop.Script macro

                          Hi ,

                           

                          thanks for reply.

                           

                          yes it is placing the script in existed application, but it is also creating an empty tab also.

                           

                          How to overcome the creating an empty tab.

                           

                          it looks like below :

                           

                          Thanks in advance.

                           

                          empty tab.JPG

                            • Re: docprop.Script macro
                              Celambarasan Adhimulam

                              Hi,

                                   Check with the below script where Empty tab gets fixed.

                               

                              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)=ArrayScript(i) & chr(10) & "$(Include=d:\vqd eat\text\test.txt);"

                              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

                                • Re: docprop.Script macro

                                  Hi,

                                   

                                  that's really great.

                                   

                                  it is removing the empty tabs, but when i click the macro button every time it is adding the same script line repeatedly.

                                   

                                  But it should replace the script line in "Main 2" tab. i.e; if n number of times i run the macro it should replace in"Main 2" tab with single script line.

                                   

                                  Thanks in advance.

                                    • docprop.Script macro
                                      Celambarasan Adhimulam

                                      Hi

                                           Then you going to add Only new scripts to that tab?

                                      If so use the below script

                                       

                                      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) & "$(Include=d:\vqd eat\text\test.txt);"

                                      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

                                        • Re: docprop.Script macro

                                          Hi,

                                           

                                          Awesome !!! Thanks a lot, you solved my three days problem now.

                                           

                                          please if you don't mind i had one more doubt i.e; if we want to add script line at particular line number how we can do it ?

                                           

                                          Consider that we are planning to add script line at line number "4" in "Main 2" tab.

                                          And if already a script line present at line number 4 it should replace with newly added line script

                                          or

                                          if no line number "4" present in "Main 2" tab then need to add line number "4" and new line script should add.

                                           

                                          is it possible ?

                                           

                                          Thanks in advance.

                                            • Re: docprop.Script macro
                                              Celambarasan Adhimulam

                                              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

                                                • Re: docprop.Script macro

                                                  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

                                                    • Re: docprop.Script macro

                                                      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

                                                      • Re: docprop.Script macro
                                                        Perumal Ayyappan

                                                        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

                                                        • Re: docprop.Script macro
                                                          Celambarasan Adhimulam

                                                          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

                                                            • Re: docprop.Script macro

                                                              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

                                                                • docprop.Script macro
                                                                  Celambarasan Adhimulam

                                                                  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

                                                                    • Re: docprop.Script macro

                                                                      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

                                                                        • Re: docprop.Script macro
                                                                          Celambarasan Adhimulam

                                                                          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

                                                                            • Re: docprop.Script macro

                                                                              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

                                                                                • docprop.Script macro
                                                                                  Celambarasan Adhimulam

                                                                                  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

                                                                                  • docprop.Script macro
                                                                                    Celambarasan Adhimulam

                                                                                    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