Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default SETTING PRINT AREA IN VBA

I'm a beginner in Excel VBA. I have come across problem
to set the selected print area as follows :

ActiveSheet.PageSetup.PrintArea = "Range(Activecell,
Activecell.End(xlDown))"

It seems VBA only accepts absolute address :

ActiveSheet.PageSetup.PrintArea = "$B$4:$H$16"


Please give me some clues for setting a relative reference
print area instead of an abosolute one.

Thanks.


Rgds,
Frankie
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default SETTING PRINT AREA IN VBA

Hi Frankie
ActiveSheet.PageSetup.PrintArea = ActiveCell.Address(False, False) & ":" &
ActiveCell.End(xlDown).Address(False, False)

Cordially
Pascal

"Frankie" a écrit dans le message de
...
I'm a beginner in Excel VBA. I have come across problem
to set the selected print area as follows :

ActiveSheet.PageSetup.PrintArea = "Range(Activecell,
Activecell.End(xlDown))"

It seems VBA only accepts absolute address :

ActiveSheet.PageSetup.PrintArea = "$B$4:$H$16"


Please give me some clues for setting a relative reference
print area instead of an abosolute one.

Thanks.


Rgds,
Frankie



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SETTING PRINT AREA IN VBA

Frankie,

I assume you want to set the printarea from A1 to the last cell in th
sheet. The code below selects the last cel
(ActiveCell.SpecialCells(xlLastCell).Select) and assigns its rownumbe
to the variable Lastrow. (Lastrow = Selection.Row). Then the strin
"SelString" defining the range to be selected is made from tha
variable (SelString = "A1:D" & Lastrow). This should do the trick.


Code
-------------------

Sub SetPrintArea

Dim Lastrow As Double
Dim SelString As String

ActiveCell.SpecialCells(xlLastCell).Select
Lastrow = Selection.Row
SelString = "A1:D" & Lastrow

ActiveSheet.PageSetup.PrintArea = SelString

End Sub

-------------------


Good luc

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default SETTING PRINT AREA IN VBA

do the trick? what trick?

your code makes 4 errors:

1: it will NEVER print more then 4 columns
2, it uses select where it needn't
3: it uses a lastrow variable which isn't needed either
4: it dims a row number as double????



to print the entire sheet just clear the Printarea:

ActiveSheet.PageSetup.PrintArea = ""





keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


Binzelli wrote:

Frankie,

I assume you want to set the printarea from A1 to the last cell in the
sheet. The code below selects the last cell
(ActiveCell.SpecialCells(xlLastCell).Select) and assigns its rownumber
to the variable Lastrow. (Lastrow = Selection.Row). Then the string
"SelString" defining the range to be selected is made from that
variable (SelString = "A1:D" & Lastrow). This should do the trick.


Code:
--------------------

Sub SetPrintArea

Dim Lastrow As Double
Dim SelString As String

ActiveCell.SpecialCells(xlLastCell).Select
Lastrow = Selection.Row
SelString = "A1:D" & Lastrow

ActiveSheet.PageSetup.PrintArea = SelString

End Sub

--------------------


Good luck


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SETTING PRINT AREA IN VBA

KeepITCool.... what's wrong with you mate ? Just trying to help
eachother here or not ?

Frankie asked Please give me some clues for setting a relative reference

The code does just that. Your example just prints the entire sheet, not
quite what Frankie asked.

And for your 4 ERRORS:

1. It will indeed NEVER print more than 4 columns

Thats right, it's an example, remember ! Frankie can use whatever Range
(rows and columns) he likes. The code gives - as Frankie asked - a clue
for setting a relative reference
2, it uses select where it needn't

Sure ! Learning all the time ! Next time I'll use:

Code:
--------------------
Lastrow = ActiveCell.SpecialCells(xlLastCell).Row
--------------------

3: it uses a lastrow variable which isn't needed eitherSo what do you suggest ?


Code:
--------------------
ActiveSheet.PageSetup.PrintArea = "A1:D" & ActiveCell.SpecialCells(xlLastCell).Row
--------------------
more easy and nice and compact, but as Frankie said he was new to Excel
VBA, I thought the step-by-step approach makes things a bit more easy
to understand.
4: it dims a row number as double????

Should have been "Long"

Anyway, hope your next reaction is a bit more friendly.

Beetje collegialiteit kan geen kwaad Jurgen !

Groeten uit Amsterdam


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default SETTING PRINT AREA IN VBA

Dear Pascal,

Thanks for your help.

This is the solution that I needed. It is simple and
straightforward for a beginner like me.


Rgds,
Frankie

-----Original Message-----
Hi Frankie
ActiveSheet.PageSetup.PrintArea = ActiveCell.Address

(False, False) & ":" &
ActiveCell.End(xlDown).Address(False, False)

Cordially
Pascal

"Frankie" a écrit

dans le message de
...
I'm a beginner in Excel VBA. I have come across

problem
to set the selected print area as follows :

ActiveSheet.PageSetup.PrintArea = "Range(Activecell,
Activecell.End(xlDown))"

It seems VBA only accepts absolute address :

ActiveSheet.PageSetup.PrintArea = "$B$4:$H$16"


Please give me some clues for setting a relative

reference
print area instead of an abosolute one.

Thanks.


Rgds,
Frankie



.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default SETTING PRINT AREA IN VBA

Ok Frankie glad to help

Cordially
Pascal

"Frankie" a écrit dans le message de
...
Dear Pascal,

Thanks for your help.

This is the solution that I needed. It is simple and
straightforward for a beginner like me.


Rgds,
Frankie

-----Original Message-----
Hi Frankie
ActiveSheet.PageSetup.PrintArea = ActiveCell.Address

(False, False) & ":" &
ActiveCell.End(xlDown).Address(False, False)

Cordially
Pascal

"Frankie" a écrit

dans le message de
...
I'm a beginner in Excel VBA. I have come across

problem
to set the selected print area as follows :

ActiveSheet.PageSetup.PrintArea = "Range(Activecell,
Activecell.End(xlDown))"

It seems VBA only accepts absolute address :

ActiveSheet.PageSetup.PrintArea = "$B$4:$H$16"


Please give me some clues for setting a relative

reference
print area instead of an abosolute one.

Thanks.


Rgds,
Frankie



.



Reply
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
Print Area Setting RozBuds Excel Discussion (Misc queries) 3 February 19th 10 09:41 PM
Setting The Print-Area ? Robert11[_3_] New Users to Excel 2 May 31st 09 03:24 PM
Setting print area richzip Excel Discussion (Misc queries) 1 April 27th 08 08:10 AM
Excel VBA - Setting Print Area in VB spikel Excel Programming 2 April 23rd 04 04:10 PM
Setting print area Don Guillett[_4_] Excel Programming 0 September 4th 03 02:14 PM


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

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

About Us

"It's about Microsoft Excel"