From variable to excel constant

C

Carmen

In an excel sheet I'm allowing users to pick from dropdown whether they want
to print in xlPortrait or xlLandscape. It's not feasible to go directly to
Page setup because this page setup that we are applying is for another file.

However, when I read this choice to a variable and setting
pagesetup.orientation to this variable, it doesn't recognize it. This is
because xlPortrait should not be a text, but a constant.

Is there a formula to convert the string to constant? I must allow user to
do the selection in the worksheet.

Thanks,
Carmen
 
C

carlo

Try not to apply the text xlPortrait, but the integer of this
constant.

xlPortrait = 1
xlLandscape = 2

hth

Carlo
 
J

Joel

xlPortrait is a number and can't be treated as text.. This means it can't be
combined into a text string and can't be inside a double quoted string. It
also can't be selectect be inside a textbox.

You can do something like this

From a drop down box put Portriat or Landscape

select case Range("A1") 'or a textbox which has Portriat or Landscape
case "Portrait"
printmode = xlPortrait
case "Landscape"
printmode = xlLandscape
end select

pagesetup.orientation = printmode

or
select case Range("A1") 'or a textbox which has Portriat or Landscape
case "Portrait"
pagesetup.orientation = xlPortrait
case "Landscape"
pagesetup.orientation = xlLandscape
end select

The use printmode which is a number in your print command.
 

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