regex - vbscript: replace text in activedocument with hyperlink -
starting out @ new job , have go through whole lot of documents predecessor left. ms word-files contain info on several hundreds of patents. instead of copy/pasting every single patent-number in online form, replace patent-numbers clickable hyperlink. guess should done vbscript (i'm not used working ms office).
i have far:
<obsolete>
this not working me: 1. (probably) need add together loop through activedocument 2. replace-function needs string , not object parameter - there __tostring() in vbscript?
thx!
update: have partially working (regex , finding matches) - if anchor hyperlink.add-method right...
sub hyperlinkpatentnumbers() ' ' hyperlinkpatentnumbers macro ' dim objregexp, matches, match, myrange set myrange = activedocument.content set objregexp = createobject("vbscript.regexp") objregexp .global = true .ignorecase = false .pattern = "(wo|ep|us)([0-9]*)(a1|a2|b1|b2)" end set matches = objregexp.execute(myrange) if matches.count >= 1 each match in matches activedocument.hyperlinks.add anchor:=objregexp.match, address:="http://worldwide.espacenet.com/publicationdetails/biblio?db=epodoc&adjacent=true&locale=en_ep&cc=$1&nr=$2&kc=$3" next end if set matches = nil set objregexp = nil end sub
is vba or vbscript? in vbscript cannot declare types dim newtext hyperlink
, every variable variant, so: dim newtext
, nil more.
objregex.replace
returns string replacements , needs 2 parameters passed it: original string , text want replace pattern with:
set objregex = createobject("vbscript.regexp") objregex.global = true objregex.ignorecase = false objregex.pattern = "^(wo|ep|us)([0-9]*)(a1|a2|b1|b2)$" ' assuming plaintext contains text want create hyperlink strname = objregex.replace(plaintext, "$1$2$3") straddress = objregex.replace(plaintext, "http://worldwide.espacenet.com/publicationdetails/biblio?db=epodoc&adjacent=true&locale=en_ep&cc=$1&nr=$2&kc=$3"
now can utilize strname
, straddress
create hyperlink with. pro-tip: can utilize objregex.test(plaintext)
see if regexp matches handling of errors.
regex vbscript hyperlink
No comments:
Post a Comment