LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 417
Default Print Macro with two drop-down lists

Here is a more correct version, since Forms Controls on a worksheet (in
Excel 2000) are contained inside a shape object.

'----------------------------------------------------------------------
'Code for Excel 2000.
'Use Tools|References to set a reference
'to "Microsoft Forms 2.0 Object Library".

Public Sub PrintAllWorksheets()
Dim wsSGAComparative As Worksheet

Dim cboCategory As ControlFormat
Dim rngCategoryData As Range
Dim rngCategoryLinkedCell As Range

Dim cboConsUnit As ControlFormat
Dim rngConsUnitData As Range
Dim rngConsUnitLinkedCell As Range

Dim lngCategoryCount As Long 'Actual number of category items.
Dim lngConsUnitCount As Long 'Actual number of consunit items.

Dim ilngCategory As Long 'Index to use while printing sheets.
Dim ilngConsUnit As Long 'Index to use while printing sheets.

On Error GoTo ExitSub

Application.Calculation = xlCalculationManual

Set wsSGAComparative = Worksheets("SGA Comparative")

'Get references to drop-down combo boxes.
With wsSGAComparative
Set cboCategory = FormsControlOnWorksheet(wsSGAComparative, _
"category")
Set cboConsUnit = FormsControlOnWorksheet(wsSGAComparative, _
"consunit")
End With

'Locate category data areas.
With cboCategory
Set rngCategoryData = Application.Range(.ListFillRange)
Set rngCategoryLinkedCell = Application.Range(.LinkedCell)
lngCategoryCount = rngCategoryData _
.SpecialCells(xlCellTypeConstants) _
.Count
End With

'Locate consunit data areas.
With cboConsUnit
Set rngConsUnitData = Application.Range(.ListFillRange)
Set rngConsUnitLinkedCell = Application.Range(.LinkedCell)
lngConsUnitCount = rngConsUnitData _
.SpecialCells(xlCellTypeConstants) _
.Count
End With

For ilngCategory = 1 To lngCategoryCount
'Set the combobox value to an item from the list.
rngCategoryLinkedCell.Value = ilngCategory

For ilngConsUnit = 1 To lngConsUnitCount
rngConsUnitLinkedCell.Value = ilngConsUnit

'Insure worksheet is up-to-date before printing.
Application.Calculate

'Print the worksheet with the filled-in data.
'Change Preview parameter to True to preview before printing.
wsSGAComparative.PrintOut Preview:=False
Next ilngConsUnit
Next ilngCategory

ExitSub:
Application.Calculation = xlCalculationAutomatic
End Sub

'----------------------------------------------------------------------
Public Function FormsControlOnWorksheet(ws As Worksheet, _
strShapeName As String) _
As ControlFormat

Dim shp As Shape

On Error GoTo ExitFunction

'Attempt to get the shape that contains the Forms Control.
Set shp = ws.Shapes(strShapeName)

If shp.Type = msoFormControl _
Then
'Shape contains a Forms Control.
Set FormsControlOnWorksheet = shp.ControlFormat
Else
'Shape contains something other than a control.
Set FormsControlOnWorksheet = Nothing
End If

ExitFunction:
End Function


--
Regards,
Bill Renaud





 
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 Macro For Drop Down tojo107 Excel Discussion (Misc queries) 2 June 13th 07 03:03 PM
Print Macro for Drop Box tojo107 Excel Discussion (Misc queries) 0 April 25th 07 05:32 PM
Multiple lists with repeated values for dependet drop down lists mcmanusb Excel Worksheet Functions 1 September 29th 06 12:13 AM
Macro to add drop-down lists comparini3000 Excel Discussion (Misc queries) 1 June 8th 06 01:20 AM
drop-down lists print on a separate page in excel Kayh2 Excel Worksheet Functions 4 January 20th 06 09:51 PM


All times are GMT +1. The time now is 11:15 AM.

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"