Add page number in Word using VBA -


i looking hours 1 of simplest things (but ms things never simple...): how can programmatically add in word footer 'page #', using vba ?
there zillions of different ways on internet none working. couple of examples

code fails @ fields.add:

sub pagenumber()     activedocument.sections(activedocument.sections.count) _         .headers(wdheaderfooterprimary).range.select     selection         .paragraphs(1).alignment = wdalignparagraphcenter         .typetext text:="page "         .fields.add range:=selection.range, type:=wdfieldempty, text:= _             "page ", preserveformatting:=true         .typetext text:=" of "         .fields.add range:=selection.range, type:=wdfieldempty, text:= _             "numpages ", preserveformatting:=true     end end sub 

this code doesn't allow me add word 'page' before:

with activedocument.sections(1)   .footers(wdheaderfooterprimary).pagenumbers.add _   pagenumberalignment:=wdalignpagenumberleft, _   firstpage:=true  end 

any additional hint ?
thanks.

ok, following code works:

with objword.activedocument.sections(section)     .footers(wdheaderfooterprimary).range.text = vbtab & "page "     .footers(wdheaderfooterprimary).pagenumbers.add firstpage:=true end 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -