LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Cases/Set object to take coordinates of Print Range

Bruce,

Excel can be very tempermental. Variables have to be defined carefully.
For your needs:
1. Your workbook must be the active workbook.
2. The worksheet must be selected.
3. Than you can select the range.

-----------------------------------------------------
Dim mysheet As Worksheet, Printthisrange as Range
'
Set mysheet = Worksheets("OBA TWML")
Set Printthisrange = mysheet.Range("G5:M25")
' (reset the range per your needs)

mysheet .Select
Printthisrange.select

Set Printthisrange = Nothing
Set mysheet = Nothing
-----------------------------------------

If this still doesn't work. Double check that all your variables are
picking up the correct values. Make sure that Option Explicit is
at the top of the module. And Debug Compile your project to
see if Excel can pick up any problems.

Put the code above in a module all by itself and see if it runs.

This shouldn't have been this hard. I have a lot of other
stuff to do they may make this look like a walk in the
park. So, it is real frustrating that the learning curve
is so steep going from QPW to Excel. There wasn't a whole
lot in QPW that I couldn't do.


Part of the problem was the problem you were having with the syntax.
Had to repeat myself a few times (myfault) about setting the Case
statements.
And than you didn't realize that you needed to replace some of my "names"
with your "names". This stuff happens...

And sometimes typo's and such really get in the way. This is why debugging
and stepping through code is so important.

I don't know what QPW is but I don't think you can really compare the two.
At the beginning Excel VB can be a bit confusing. But once you get on with
it - it does get easier. It is a steep curve because there is a lot to
learn!
Spend as much time as you can reading as many of the posts in the ng
and you will be surprised.

steve

"Bruce Roberson" wrote in message
...
Steve:

Then shouldn't I be able to assign a sheet name to mysheet
having already declared that as a worksheet object?

For the last case option, the sheet name in question would
be OBA TWML (Space intentional betw A and T). So, right
after that statement, I have tried various syntax with no
luck so far.

Case OptTWMLOBA.Value
Set Printthisrange = Range("OBATWML")
Set mysheet = Worksheet("OBA TWML")

If it takes that, then I should be able to select the
sheet and/or the range itself, right? Then, if I get all
accomplished, then I can do what I need to with the print
settings.

This shouldn't have been this hard. I have a lot of other
stuff to do they may make this look like a walk in the
park. So, it is real frustrating that the learning curve
is so steep going from QPW to Excel. There wasn't a whole
lot in QPW that I couldn't do.

Bruce



Case
-----Original Message-----
Bruce,

You need to substitute the actual name of the sheet in

place of MySheet.
(MySheet is just a generic). Excel is looking for the

name you have
assigned to the sheet.

You may see things like MyRange, MySheet, MyBook in

posted code. You must
always replace these with the names you are using. You

may also see
references to $A1:$G$5 in the posted code. Again you

must replace this with
the range you are using.

Remember we don't always know what your workbook looks

like (or for that
matter, what other peoples workbooks look like). So we

construct code with
generic references. Unfortunately many of the new comers

aren't familiar
with this and get caught.

Hope this helps...

steve

"Bruce Roberson" wrote in

message
...
I'd love to do somethign with a Sheets command, but it
always gives me an idiot message, in this case Run time
message 13

Private Sub btnprint1_Click()
Dim Printthisrange
Dim mysheet As Worksheet

Select Case True
Case OptCNGOBA.Value
Set Printthisrange = Range("OBACGG")
Case OptDEFSOBA.Value
Set Printthisrange = Range("OBADEFS")
Case OptAgaveOBA.Value
Set Printthisrange = Range("OBAAgave")
Case OptTWMLOBA.Value
Set Printthisrange = Range("OBATWML")

End Select

__________________________________________________ _______
Well how do I get it to recognize "Mysheet" as a

reference?


Sheets("mysheet").Printthisrange.Select

With Sheets("MySheet").Printthisrange
.PrintTitleRows = ""
.PaperSize = xlPaperLegal
.FitToPagesWide = 1
.FitToPagesTall = 1
.Orientation = xlLandscape
End With
Unload Me
Printthisrange.Select
Printthisrange.PrintPreview
Printthisrange = "Nothing"
Range("a1").Select


End Sub




.



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula for Cases=144 * # of Cases + Pieces Inventory Formula Excel Discussion (Misc queries) 2 December 29th 09 09:09 PM
Used to be able to attach range of labels to xy coordinates - no m 2007 Excels sucks99999[_2_] Charts and Charting in Excel 1 October 24th 09 11:06 AM
Print Word Object in Excel Mac Excel Discussion (Misc queries) 7 March 2nd 07 05:12 PM
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
Print Macro : Object not set Ugleeduck Excel Programming 2 July 19th 03 11:10 PM


All times are GMT +1. The time now is 12:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"