Can a variable be used to construct a built-in constant?

  • Thread starter Victor Boris Arnold
  • Start date
V

Victor Boris Arnold

Word version: 2000.

I have some code where a style is assigned to the
selection (e.g., Selection.Style = wdStyleHeading1). What
I'd like to be able to do is vary the actual style used--
sometimes I'll use wdStyleHeading1, sometimes
wdStyleHeading2, etc. But I want to be able to specify the
particular constant via an argument passed to the
subroutine. So the variable would be constructed
as "wdStyleHeading" & Number. This would then have to be
evaluated as a built-in constant (I think like the eval
function available in some programming languages).

Is this possible with Word VBA?
 
J

Jonathan West

Victor Boris Arnold said:
Word version: 2000.

I have some code where a style is assigned to the
selection (e.g., Selection.Style = wdStyleHeading1). What
I'd like to be able to do is vary the actual style used--
sometimes I'll use wdStyleHeading1, sometimes
wdStyleHeading2, etc. But I want to be able to specify the
particular constant via an argument passed to the
subroutine. So the variable would be constructed
as "wdStyleHeading" & Number. This would then have to be
evaluated as a built-in constant (I think like the eval
function available in some programming languages).

Is this possible with Word VBA?

Basically no. If a constant has a variable element, it's no longer constant.
Simply pass the constant to the subroutine as the value of the parameter,
like this

Sub MyHeadingRoutine(HeadingToBePassed as wdBuiltInStyle)
'put yout code here
End sub

to call the routine, just do this

MyHeadingRoutine wdStyleHeading1

or

MyHeadingRoutine wdStyleHeading2
 

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