Can't set footnote in Word doc using Excel VBA -


i have numerous word documents have several content controls in them. using excel file update word docs. when make update, need insert footnote describing change. can update contents of content control fine, having problems inserting footnote. here's code:

set cc = orange.contentcontrols(intcounter) stroriginaldate = cc.range.text  if wrddoc.protectiontype <> wdnoprotection     wrddoc.unprotect strsheetpassword end if  if wrddoc.formsdesign = false     wrddoc.toggleformsdesign end if cc.range.text = strcod ' ' insert footnote ' orange = wrddoc.range(cc.range.end, cc.range.end) orange.select selection.moveright units:=wdcharacter, count:=1 selection.typetext text:=" " selection     .footnoteoptions         .location = wdbottomofpage         .numberingrule = wdrestartcontinuous         .startingnumber = 1         .numberstyle = wdnotenumberstylearabic         .layoutcolumns = 0     end     .footnotes.add range:=cc.range, text:="case opening date changed " & _     stroriginaldate & " " & strcod & " on " & date, reference:=""     end if end  wrddoc.toggleformsdesign wrddoc.protect type:=wdallowonlyformfields, password:=strsheetpassword wrddoc.save 

when down line selection.moveright units:=wdcharacter, count:=1, error says object doesn't support property or method. in essence, i'm trying move end of control, on next step, i'm trying move beyond/outside control.

when comment out line , line follows it, end trying insert footnote content control. fails on with .footnoteoptions line, possibly because content control i'm using date picker.

you correct can't add footnote inside of content control. solution trying - put in document after. problem trying add using selection object.

since have range within context of document (orange), work directly:

' ' insert footnote '  'move orange "insertion point" after control. orange.start = cc.range.end + 1 'collapse it. orange.end = orange.start 'add space. orange.text = " "  orange.footnoteoptions     .location = wdbottomofpage     .numberingrule = wdrestartcontinuous     .startingnumber = 1     .numberstyle = wdnotenumberstylearabic     .layoutcolumns = 0 end  orange.footnotes.add range:=orange, text:="case opening date changed " & _                      stroriginaldate & " " & strcod & " on " & date 

there's no reason mucking around selection - it's glorified range added benefit of doing annoying things word "for benefit" (like grabbing trailing space) while you're highlighting mouse.

i'll note can omit reference:="" - gets set empty string default. have floating end if inside block.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -