How do I define a range?

A

Al

I would like to go to a bookmark which marks the beginning of the range and
from that point define the end point to be 10 characters to the right.

What is the syntax for this please?
 
D

Dave Lett

HI Al,

You can use something like the following:

Dim oRng As Range
Set oRng = ActiveDocument.Bookmarks("Test").Range
oRng.End = oRng.Start + 10
oRng.Select

HTH,
Dave
 
A

Al

OK, this works from Word; however, what would the syntax for the "Dim oRng As
Range" statement be in Access? Range is not declarable in Access directly.

There must be a way to declare oRng as Word.range
 
D

Dave Lett

Hi Al,

"OK, this works from Word"; well, it is a Word newsgroup.
When you're viewing a module in Access, open the Tools menu and click
References. From the list of Available References, select Microsoft Word X.X
Object Library, where X.X is your version of Word.

HTH,
Dave
 
H

Helmut Weber

Hi everybody,

and in addition declare the range as a word range.

Like, with references set:

Sub test4567()
'reference set !
Dim oWrd As Word.Application
Dim oDoc As Word.Document
Dim oRng As Word.Range
Set oWrd = New Word.Application
Set oDoc = oWrd.Documents.Add
Set oRng = oDoc.Range
oWrd.Visible = True
oDoc.Range.Text = String(10, "x")
oDoc.Range.InsertAfter String(900, "y")
oRng.Start = 0
oRng.End = 10
MsgBox oRng.Text
End Sub



Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
A

Al

Dave (and all) thankyou for your reply. I found the problem and was able to
program a solution.

The problem is that according to MS Access documentation, some MS Word
ranges cannot be set from MS Access. If the bookmark is located in an MS
Word table then ranges usually work. This is apparently the problem because
my bookmark was just located on the page where a normal zip code usually
lives right after the state.


So in MS Word I built a 1 cell table and placed in an innocuous part of the
document where it would not affect anything. I selected the cell contents
and set a bookmark named "ZipCode". I hide the table by making the font
hidden, and setting borders and shading to none.

Below the city, state zip line I added a barcode field on a new line that
references the ZipCode bookmark. It looks like this:
{BARCODE ZipCode \b \u \* MERGEFORMAT}

Now this MS Access code works:

(Look at the Set oRng section. This is the MS Word VBA code):

Dim appword, Docs, prps As Object
Dim oRng As Word.Range

Set appword = CreateObject("Word.Application")
Set Docs = appword.Documents
Docs.Add strSched

Set oRng = ActiveDocument.Bookmarks("ZipCode").Range
oRng.Text = [strProdZipBus]
ActiveDocument.Bookmarks.Add "ZipCode", oRng

Thanks again Dave,

Hope this helps you and others!!

Al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top