Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Setting print area

I am trying to set up a macro that sets the print area. I tried getting the
code by using "record new macro", and copying my keystrokes. I highlighted
the area I want to print, and recorded the keystrokes from there.

The macro came out to be:

ActiveSheet.PageSetup.PrintArea = "$A$1:$G$35"

However, the actual area will vary depending on the worksheet. How can I
change this code to make the area = only what I have highlighted at the time
I start the macro?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Setting print area

Hi,

Try this

ActiveSheet.PageSetup.PrintArea = Selection.Address

Mike

"richzip" wrote:

I am trying to set up a macro that sets the print area. I tried getting the
code by using "record new macro", and copying my keystrokes. I highlighted
the area I want to print, and recorded the keystrokes from there.

The macro came out to be:

ActiveSheet.PageSetup.PrintArea = "$A$1:$G$35"

However, the actual area will vary depending on the worksheet. How can I
change this code to make the area = only what I have highlighted at the time
I start the macro?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Setting print area

Hi Richzip,

You can add 2 lines to your code to retrieve the current selection address
and modify your code to reference the retrieved selection address.

Dim rg As Range ' variable to hold the current selection
Set rg = Selection ' get the range of the current selection
ActiveSheet.PageSetup.PrintArea = rg.Address

'Complete working code:
Sub SetPrintArea()
'Make sure selection is a Range object
If TypeName(Selection) = "Range" Then
'Create rg variable and store the current selection address
Dim rg As Range
Set rg = Selection
'Set the print area
ActiveSheet.PageSetup.PrintArea = rg.Address
Else
MsgBox "The current selection cannot be use to set as print area."
End If
End Sub

Hong Quach

"richzip" wrote:

I am trying to set up a macro that sets the print area. I tried getting the
code by using "record new macro", and copying my keystrokes. I highlighted
the area I want to print, and recorded the keystrokes from there.

The macro came out to be:

ActiveSheet.PageSetup.PrintArea = "$A$1:$G$35"

However, the actual area will vary depending on the worksheet. How can I
change this code to make the area = only what I have highlighted at the time
I start the macro?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Setting print area

Unless you are going to use the print range for other purposes, it is not
necessary to set it if you only want to print the selection. You can just
use:

Selection.PrintOUt

It will only print the selected range.

"richzip" wrote:

I am trying to set up a macro that sets the print area. I tried getting the
code by using "record new macro", and copying my keystrokes. I highlighted
the area I want to print, and recorded the keystrokes from there.

The macro came out to be:

ActiveSheet.PageSetup.PrintArea = "$A$1:$G$35"

However, the actual area will vary depending on the worksheet. How can I
change this code to make the area = only what I have highlighted at the time
I start the macro?

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
Setting Print Area DavidH56 Excel Programming 5 January 24th 09 05:46 AM
setting up the print area Gina Excel Programming 1 July 13th 06 06:10 PM
setting print area Nick Smith[_2_] Excel Programming 3 April 26th 06 10:39 AM
Setting the print area Patch61 Excel Programming 5 April 18th 06 04:42 PM
Setting Print Area dolppm Excel Programming 2 March 8th 05 09:35 PM


All times are GMT +1. The time now is 02:40 AM.

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"