How to generate _Ref autonumber?

G

Guest

Hi,

I'm adding references to a document and would like to generate (to keep it
consistent with what word creates) the _Ref autonumber.

Does anybody know if it's accessible through any functions etc.?

Thanks,

R.
 
D

Dave Lett

Hi,

Rnd will raise an error by itself because it returns values between zero and
one. You can use something like the following to test for the existence of a
bookmark and then add one, using a random number:

Dim iRandom As Integer
iRandom = Int((10000 - 1 + 1) * Rnd + 1)
Do While ActiveDocument.Bookmarks.Exists("_Ref" & iRandom)
iRandom = Int((10000 - 1 + 1) * Rnd + 1)
Loop
ActiveDocument.Bookmarks.Add Name:="_Ref" & iRandom

HTH,
Dave
 
J

Jean-Guy Marcil

Dave Lett was telling us:
Dave Lett nous racontait que :
Hi,

Rnd will raise an error by itself because it returns values between
zero and one. You can use something like the following to test for
the existence of a bookmark and then add one, using a random number:

Dim iRandom As Integer
iRandom = Int((10000 - 1 + 1) * Rnd + 1)
Do While ActiveDocument.Bookmarks.Exists("_Ref" & iRandom)
iRandom = Int((10000 - 1 + 1) * Rnd + 1)
Loop
ActiveDocument.Bookmarks.Add Name:="_Ref" & iRandom

Sorry to be picky, but..
Why
iRandom = Int((10000 - 1 + 1) * Rnd + 1)
???
Souldn't it be:
iRandom = Int((10000 * Rnd) + 1)
???

I mean
10000 - 1 + 1 always equals 10000
No?

And, could we use:
iRandom = Int(10000 * Rnd)
It seems to give the same result.

I am not very good with Maths...this is why I am asking!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

Dave Lett

Not picky, just an excellent eye.
I used the example in the MS Help file topic Rnd Function. In that topic,
the example is

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Here, upperbound is the highest number in the range, and lowerbound is the
lowest number in the range.


Instead of passing values for upperbound and lowerbound, I simply changed
the values and didn't take the time to review the line for, well,
intelligence.

Dave
 
J

Jean-Guy Marcil

Dave Lett was telling us:
Dave Lett nous racontait que :
Not picky, just an excellent eye.
I used the example in the MS Help file topic Rnd Function. In that
topic, the example is

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Here, upperbound is the highest number in the range, and lowerbound
is the lowest number in the range.


Instead of passing values for upperbound and lowerbound, I simply
changed the values and didn't take the time to review the line for,
well, intelligence.

LOL
Don't worry, it happens to all of us!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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