Generalizing the methods


hello everyone.......

i have  a word document contains table , in each row of table have 2 dropdowns (in column 6 , column 7) , textbox (column 8).

rite m doing each row formed function(e.g,f1 row 1 ,f2 row2 ,etc) takes value of dropdowns , multiply , show in textbox.

now have generalize function each row in table ,so whenever new row added table ,the function should applicable .

please me need urgently

thanxs in advance.............!!!

hi ruhi,

after adding row , formfields in columns 6 & 7, run following code:

sub demo()
application.screenupdating = false
dim strff1 string, strff2 string, ofld field
dim long, rng1 range, rng2 range
activedocument.tables(1)
  = .rows.count
  strff1 = "ref " & .rows(i).cells(6).range.formfields(1).name
  strff2 = "ref " & .rows(i).cells(7).range.formfields(1).name
  set rng1 = .rows(i).cells(8).range
  rng1.end = rng1.end - 1
  set ofld = activedocument.fields.add(rng1, wdfieldempty, "=* \# 0", false)
  ofld
    .showcodes = true
    set rng1 = .code
    = instr(.code, "=")
    rng1
      .start = .start + i
      .collapse wdcollapsestart
    end with
    set rng2 = .code
    = instr(.code, "*")
    rng2
      .start = .start + i
      .collapse wdcollapsestart
    end with
    activedocument.fields
      .add rng2, wdfieldempty, strff2, false
      .add rng1, wdfieldempty, strff1, false
    end with
    .showcodes = false
    .update
  end with
end with
set rng1 = nothing: set rng2 = nothing
application.screenupdating = true
end sub

note: code doesn't use formfield column 8 - uses formula field instead, that's more reliable if further calculations based on result needed.


cheers
paul edstein
[ms mvp - word]


Microsoft Office  >  Word IT Pro Discussions



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group