macros - Outputting Drop-Down Form Field to String for use in VBA formula -


ok, have word 2010 template i'm playing with. have button @ top users click automatically save word doc pdf (almost) correct name, in correct directory, , opens doc. have drop-down form field can select month.

the code button:

private sub commandbutton1_click()     convert_pdf end sub   sub convert_pdf()   dim desktoploc string  dim filename string  dim date string  dim user string  dim mypath string      desktoploc = createobject("wscript.shell").specialfolders("desktop")     filename = "installs team metrics"     user = vba.environ("username")     mypath = desktoploc & "\metrics\" & filename & " - " & date & " - " & user      activedocument.exportasfixedformat outputfilename:= _         mypath, _         exportformat:=wdexportformatpdf, openafterexport:=true, optimizefor:= _         wdexportoptimizeforprint, range:=wdexportalldocument, from:=1, to:=1, _         item:=wdexportdocumentcontent, includedocprops:=true, keepirm:=true, _         createbookmarks:=wdexportcreatenobookmarks, docstructuretags:=true, _         bitmapmissingfonts:=true, useiso19005_1:=false end sub 

this outputs file c:\users[username]\desktop\metrics\installs team metrics - [month] - [username].pdf

biggest problem is, cant figure out how whats selected in dropdown box string "date". have feeling i'm using wrong 1 (pretty sure need activex control one) i'm new vba , appreciate help.

looks content control rather legacy field, need

activedocument.contentcontrols(i).range.text

where index no. of control (the first 1 in document 1, etc.)

so either need know number, or need use title or tag of control (or else) identify control. in case of content controls, have iterate collection find it, e.g.

dim cc contentcontrol each cc in activedocument.contentcontrols   if cc.tag = "mytag"     strdate = cc.range.text     exit   end if next 

be careful how title/tag controls. word not enforce uniqueness of either titles or tags.

another way create custom xml part "date" element , connect control using xpath. can retrieve value directly custom xml part , don't need know control itself. think in simple form adds complications can without.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -