Hello,

I'm trying to create a macro that will prompt a user for a zip code (5 or 9
character) and then insert a bar code. Here's what I have so far:

Sub MyBarCode()

Dim MyZipCode As String

MyZipCode = InputBox("Enter Zip Code")

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"BARCODE \u MyZipCode ", PreserveFormatting:=True
End Sub

The macro runs and I enter a valid zip code but here's what I get at the
cursor instead of a bar code:

'Zip Code Not Valid!

I think the "\u MyZipCode" is the problem but I don't know how to fix it.

Any help is appreciated. Thank you.

Re: Input box and bar code field by Graham

Graham
Tue Sep 18 03:27:28 CDT 2007

MyZipCode will never be a zip code in the field. Although we don't use
barcodes on this side of the pond

"BARCODE \u " & MyZipCode,

would probably be nearer the mark, however the barcode produced by Word is
POSTNET.

The USPS no longer accepts that format for bulk mail discounts -- see
http://support.microsoft.com/kb/897290. You might as well not use the
barcode feature at all.


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Sammy wrote:
> Hello,
>
> I'm trying to create a macro that will prompt a user for a zip code
> (5 or 9 character) and then insert a bar code. Here's what I have so
> far:
>
> Sub MyBarCode()
>
> Dim MyZipCode As String
>
> MyZipCode = InputBox("Enter Zip Code")
>
> Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
> Text:= _ "BARCODE \u MyZipCode ", PreserveFormatting:=True
> End Sub
>
> The macro runs and I enter a valid zip code but here's what I get at
> the cursor instead of a bar code:
>
> 'Zip Code Not Valid!
>
> I think the "\u MyZipCode" is the problem but I don't know how to fix
> it.
>
> Any help is appreciated. Thank you.