Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Print Macro For Drop Down | Excel Discussion (Misc queries) | |||
Print Macro for Drop Box | Excel Discussion (Misc queries) | |||
Multiple lists with repeated values for dependet drop down lists | Excel Worksheet Functions | |||
Macro to add drop-down lists | Excel Discussion (Misc queries) | |||
drop-down lists print on a separate page in excel | Excel Worksheet Functions |