Consulting

Results 1 to 5 of 5

Thread: userform input box to print a page

  1. #1

    userform input box to print a page

    Hi

    I set up a spreadsheet with data and print numbers.

    I have a Userform that will print certain page numbers
    HTML Code:
    Private Sub CommandButton2_Click()
    Application.ScreenUpdating = False
    Sheets("Sheet1").Select
    Select Case Me.ListBox1.Value
    Case Is = "A": ActiveSheet.PrintOut From:=4, To:=6, Copies:=1
    Case Is = "B": ActiveSheet.PrintOut From:=7, To:=9, Copies:=1
    Case Is = "C": ActiveSheet.PrintOut From:=10, To:=11, Copies:=1
    Case Is = "D": ActiveSheet.PrintOut From:=13, To:=15, Copies:=1
    Case Is = "E": ActiveSheet.PrintOut From:=16, To:=18, Copies:=1
    Case Is = "F": ActiveSheet.PrintOut From:=19, To:=21, Copies:=1
    Case Is = "G": ActiveSheet.PrintOut From:=22, To:=23, Copies:=1
    ........
    I'm trying to add an input (text) box to be able to print only a particular number
    the user would put in the number that is needed to print.
    The way it works now is if ,as an example, the user needs printout >> 5, 4,5,and 6 gets printed

    I thought about making 23 list boxes and adapting the above code, but would like to make it easier for me, and learn somethi


    mike

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    The following macro will show the Windows PrintDialog form :

    Option Explicit
    
    
    Sub commandbutton1_click()
        Application.Dialogs(xlDialogPrint).Show
    End Sub

  3. #3
    You could make the list box multi-select and have as many entries in the list as you have pages, then select the pages you want to print and loop through the items in the list box and print only those that are selected e.g. as follows. Note that the first item in a list box is indexed 0 so to print the item associated with a selected list item add 1 to the index.

        Dim iLst As Integer
        For iLst = 0 To ListBox1.ListCount - 1
            If ListBox1.Selected(iLst) = True Then
                'do stuff with the selected item e.g
                ActiveSheet.PrintOut from:=iLst + 1, to:=iLst + 1, copies:=1
            End If
        Next iLst
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    Hi Logit, gmayor,

    I like them both. Great learning tools.

    Thank you both for the help.

    Mike.

  5. #5
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    You are welcome.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •