Word VBA "Label Not Defined" If Bookmark exists command -
i new vba , learning. here's situation , problem:
1) created working userform text , comboboxes linking bookmarks 2) problem doesn't work if bookmarks don't exist (and project require this: form need run on documents not bookmarks present) 3) form stop giving me error messages if bookmarks arent there , fill out ones existing in particular ocument 4) here's code:
private sub cmdok_click() application.screenupdating = false activedocument if .bookmarks.exists("cboyourname") .range.text = cboyourname.value else: goto 28 end if if .bookmarks.exists("cboyourphone") .range.text = cboyourphone.value else: goto 32 end if if .bookmarks.exists("cboyourfax") .range.text = cboyourfax.value else: goto 36 end if if .bookmarks.exists("cboyouremail") .range.text = cboyouremail.value else: goto 40 end if if .bookmarks.exists("txtcontractname") .range.text = txtcontractname.value else: goto 44 end if if .bookmarks.exists("txtcontractnumber") .range.text = txtcontractnumber.value else: end end if end application.screenupdating = true unload me end sub
4) how work?????????
i think you're close. first, avoid goto statements. in code, it's hard tell mean do. think errors goto statements. parameter label, not line number. second, avoid using end. it's better have closing routine. said, code works number of exists statements.
private sub cmdok_click() application.screenupdating = false activedocument if .bookmarks.exists("cboyourname") .range.text = "cboyourname text." else debug.print "bookmark exists." end if if .bookmarks.exists("cboyourphone") .range.text = "cboyourphone text" else debug.print "bookmark not exists." end if end application.screenupdating = true unload me end sub
however, aware each found bookmark replaces content of document, including subsequently found bookmarks. mean do?
Comments
Post a Comment