Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Active Sheet

Below is a Macro that I had written initially to just print the work sheets.
It has now evolved into not only printing but saving each work sheet as it's
own unique file. The issue that I am having is that I want to move this MACRO
to a main menu sheet. I know that if I do that the line of code for the
printing function will print the main menu page as opposed to the worksheet
page. could someone let me know what I need in order to fix the code.

Macro currently resides on Worksheet Page and I want it on the Main Menu Page.

See Macro below:

Sub Print_sheets_Click()
Dim position, max As Integer
Dim CurrentWorkbook As Workbook
Dim NewWorkbook As Workbook
Dim Rng As Range

'setting the print area
ActiveSheet.PageSetup.PrintArea = "$AB$2:$am$58"

'initialize beginning provider
position = Range("s3")

'get maximum number of providers from excel sheet
max = Range("t3")

MsgBox position & "------" & max

Do Until position max 'check if max was reached yet

'change number sequentially in Cell n3
Range("n3") = position

'sending out put to the printer
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

' Saves Individual Provider Spreadsheets
Set CurrentWorkbook = ActiveWorkbook
Set NewWorkbook = Workbooks.Open(Filename:="Test.xls")
CurrentWorkbook.Sheets(Array("E-Mail Sheet")).Copy
after:=NewWorkbook.Worksheets(1)
Set Rng = Sheets("E-Mail Sheet").Range("g1")
ActiveWorkbook.SaveAs _
Filename:=Rng.Value & ".xls", _
FileFormat:=xlWorkbookNormal
NewWorkbook.Close SaveChanges:=True

'get next provider
position = position + 1

Loop

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Active Sheet

Sub Print_sheets_Click()
Dim position, max As Integer
Dim CurrentWorkbook As Workbook
Dim NewWorkbook As Workbook
Dim Rng As Range
Dim sh as Worksheet

Set CurrentWorkbook = ActiveWorkbook
set sh = CurrentWorkbook.Sheets(Array("E-Mail Sheet"))
'setting the print area
sh.PageSetup.PrintArea = "$AB$2:$am$58"

'initialize beginning provider
position = sh.Range("s3")

'get maximum number of providers from excel sheet
max = sh.Range("t3")

MsgBox position & "------" & max

Do Until position max 'check if max was reached yet

'change number sequentially in Cell n3
sh.Range("n3") = position

'sending out put to the printer
sh.PrintOut Copies:=1, Collate:=True

' Saves Individual Provider Spreadsheets

Set NewWorkbook = Workbooks.Open(Filename:="Test.xls")
sh.Copy after:=NewWorkbook.Worksheets(1)
Set Rng = Sheets("E-Mail Sheet").Range("g1")
ActiveWorkbook.SaveAs _
Filename:=Rng.Value & ".xls", _
FileFormat:=xlWorkbookNormal
NewWorkbook.Close SaveChanges:=True

'get next provider
position = position + 1

Loop

End Sub

--
Regards,
Tom Ogilvy

"Theo Degr" wrote:

Below is a Macro that I had written initially to just print the work sheets.
It has now evolved into not only printing but saving each work sheet as it's
own unique file. The issue that I am having is that I want to move this MACRO
to a main menu sheet. I know that if I do that the line of code for the
printing function will print the main menu page as opposed to the worksheet
page. could someone let me know what I need in order to fix the code.

Macro currently resides on Worksheet Page and I want it on the Main Menu Page.

See Macro below:

Sub Print_sheets_Click()
Dim position, max As Integer
Dim CurrentWorkbook As Workbook
Dim NewWorkbook As Workbook
Dim Rng As Range

'setting the print area
ActiveSheet.PageSetup.PrintArea = "$AB$2:$am$58"

'initialize beginning provider
position = Range("s3")

'get maximum number of providers from excel sheet
max = Range("t3")

MsgBox position & "------" & max

Do Until position max 'check if max was reached yet

'change number sequentially in Cell n3
Range("n3") = position

'sending out put to the printer
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

' Saves Individual Provider Spreadsheets
Set CurrentWorkbook = ActiveWorkbook
Set NewWorkbook = Workbooks.Open(Filename:="Test.xls")
CurrentWorkbook.Sheets(Array("E-Mail Sheet")).Copy
after:=NewWorkbook.Worksheets(1)
Set Rng = Sheets("E-Mail Sheet").Range("g1")
ActiveWorkbook.SaveAs _
Filename:=Rng.Value & ".xls", _
FileFormat:=xlWorkbookNormal
NewWorkbook.Close SaveChanges:=True

'get next provider
position = position + 1

Loop

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Active Sheet

declare a worksheet variable and set it to the desired worksheet

eg.
Dim Cwb as Workbook
Dim ws as Worksheet

Set Cwb = ThisWorkbook
Set ws = Cwb.Worksheets("YourWorksheetName")

ws.PageSetup.PrintArea = "your print area"

HTH

"Theo Degr" wrote:

Below is a Macro that I had written initially to just print the work sheets.
It has now evolved into not only printing but saving each work sheet as it's
own unique file. The issue that I am having is that I want to move this MACRO
to a main menu sheet. I know that if I do that the line of code for the
printing function will print the main menu page as opposed to the worksheet
page. could someone let me know what I need in order to fix the code.

Macro currently resides on Worksheet Page and I want it on the Main Menu Page.

See Macro below:

Sub Print_sheets_Click()
Dim position, max As Integer
Dim CurrentWorkbook As Workbook
Dim NewWorkbook As Workbook
Dim Rng As Range

'setting the print area
ActiveSheet.PageSetup.PrintArea = "$AB$2:$am$58"

'initialize beginning provider
position = Range("s3")

'get maximum number of providers from excel sheet
max = Range("t3")

MsgBox position & "------" & max

Do Until position max 'check if max was reached yet

'change number sequentially in Cell n3
Range("n3") = position

'sending out put to the printer
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

' Saves Individual Provider Spreadsheets
Set CurrentWorkbook = ActiveWorkbook
Set NewWorkbook = Workbooks.Open(Filename:="Test.xls")
CurrentWorkbook.Sheets(Array("E-Mail Sheet")).Copy
after:=NewWorkbook.Worksheets(1)
Set Rng = Sheets("E-Mail Sheet").Range("g1")
ActiveWorkbook.SaveAs _
Filename:=Rng.Value & ".xls", _
FileFormat:=xlWorkbookNormal
NewWorkbook.Close SaveChanges:=True

'get next provider
position = position + 1

Loop

End Sub

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
Copy sheet and make new sheet active belvy123 Excel Discussion (Misc queries) 5 April 24th 08 03:33 PM
I need to sort an active sheet using the col of the active cell HamFlyer Excel Programming 3 June 6th 06 07:25 PM
Active Cell Copy And Paste Sheet to Sheet A.R.J Allan Jefferys New Users to Excel 4 May 4th 06 02:04 AM
Copy my active sheet to a new sheet and open with an input form Brad Withrow Excel Programming 0 April 6th 06 03:56 AM
Copy from active sheet and paste into new sheet using info from cell in active Ingve Excel Programming 3 January 23rd 06 09:57 PM


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