Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11
Default How to assign PRINT option to execute a macro

How can I assign PRINT option to execute a macro, used for printing page
numbers in a cell. Macro results a proper answer I require but only on
executing or playing macro. I want to use Print options of excel to execute
the following mentioned macro.

Sub Demo()
Dim TotalPages As Long
Dim pg As Long


TotalPages = ExecuteExcel4Macro("Get.Document(50)")
For pg = 1 To TotalPages
With ActiveSheet
.Range("BY3").Value = pg & " of " & TotalPages '<<< CHANGE HERE
.PrintOut From:=pg, To:=pg
End With
Next pg
End Sub


Kind regards,
Zubair
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default How to assign PRINT option to execute a macro

If you're wanting to code to tell XL to print a document, the easiest way is
prb to record yourself printing the document. That will record all the
different settings such as printer, paper size, which pages, etc. Adapt to
suit.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Zubair" wrote:

How can I assign PRINT option to execute a macro, used for printing page
numbers in a cell. Macro results a proper answer I require but only on
executing or playing macro. I want to use Print options of excel to execute
the following mentioned macro.

Sub Demo()
Dim TotalPages As Long
Dim pg As Long


TotalPages = ExecuteExcel4Macro("Get.Document(50)")
For pg = 1 To TotalPages
With ActiveSheet
.Range("BY3").Value = pg & " of " & TotalPages '<<< CHANGE HERE
.PrintOut From:=pg, To:=pg
End With
Next pg
End Sub


Kind regards,
Zubair

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default How to assign PRINT option to execute a macro

So do you want this macro to fire whenever the user prints? If so then you
can use the before print event. Right click on the XL icon jut to the left of
File in the XL menu. Select View Code.
Just above the code window are two drop downs. Change the one on the left to
Workbook and th eone onf the right to before print. A code stub will be
written for you that will execute any time a print event is detected.
--
HTH...

Jim Thomlinson


"Zubair" wrote:

How can I assign PRINT option to execute a macro, used for printing page
numbers in a cell. Macro results a proper answer I require but only on
executing or playing macro. I want to use Print options of excel to execute
the following mentioned macro.

Sub Demo()
Dim TotalPages As Long
Dim pg As Long


TotalPages = ExecuteExcel4Macro("Get.Document(50)")
For pg = 1 To TotalPages
With ActiveSheet
.Range("BY3").Value = pg & " of " & TotalPages '<<< CHANGE HERE
.PrintOut From:=pg, To:=pg
End With
Next pg
End Sub


Kind regards,
Zubair

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default How to assign PRINT option to execute a macro

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim TotalPages As Long
Dim pg As Long
TotalPages = ExecuteExcel4Macro("Get.Document(50)")
For pg = 1 To TotalPages
With ActiveSheet
.Range("BY3").Value = pg & " of " & TotalPages '<<< CHANGE HERE
.PrintOut From:=pg, To:=pg
End With
Next pg
End Sub

Paste into Thisworkbook module.


Gord Dibben MS Excel MVP

On Fri, 5 Feb 2010 06:21:01 -0800, Zubair
wrote:

How can I assign PRINT option to execute a macro, used for printing page
numbers in a cell. Macro results a proper answer I require but only on
executing or playing macro. I want to use Print options of excel to execute
the following mentioned macro.

Sub Demo()
Dim TotalPages As Long
Dim pg As Long


TotalPages = ExecuteExcel4Macro("Get.Document(50)")
For pg = 1 To TotalPages
With ActiveSheet
.Range("BY3").Value = pg & " of " & TotalPages '<<< CHANGE HERE
.PrintOut From:=pg, To:=pg
End With
Next pg
End Sub


Kind regards,
Zubair


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
Auto Execute Macro dennis[_2_] Excel Worksheet Functions 4 January 17th 09 04:47 PM
Print Macro both sheets at once with option to select days etc pano Excel Worksheet Functions 0 January 29th 07 04:09 AM
"assign macro" not an option from short menu SteveJ Excel Discussion (Misc queries) 2 May 18th 06 05:55 PM
Auto-execute macro.... Eric @ SEASH, Evansville Excel Discussion (Misc queries) 1 August 24th 05 09:32 PM
Execute Macro Yves Excel Discussion (Misc queries) 3 April 23rd 05 04:26 PM


All times are GMT +1. The time now is 05:55 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"