• Macro to Select & Print Selection (XP)

    Author
    Topic
    #425810

    Can someone help me write a macro that would:

    1. Do a GoTo so I can select the area of my worksheet to print
    2. Then print that selection

    In QuattroPro (which I am migrating from), I just enter the area in the print area section of the print menu. Excel doesn’t seem to have this alternative.

    I’m a real newbie at actually writing macros (I have recorded a few that do work).

    Thank you!

    Viewing 1 reply thread
    Author
    Replies
    • #982165

      Does this do what you want:


      Public Sub SelectAndPrint()
      Dim oRng As Range
      Set oRng = Application.InputBox(Prompt:="Select range to Print", Type:=8)
      oRng.PrintOut
      End Sub

      • #982175

        That works great! Thank you so much.

        Now I’m curious: What is the “Type:=8” mean? I assume it means Type is assigned 8 but what’s 8? Are there other choices?

        Appreciate the extremely fast reply.

        • #982181

          From the help on Application.InputBox method

          Type   Optional Variant. Specifies the return data type. If this argument is omitted, 
          the dialog box returns text. Can be one or a sum of the following values.
          
          Value Meaning 
          0 A formula 
          1 A number 
          2 Text (a string) 
          4 A logical value (True or False) 
          8 A cell reference, as a Range object 
          16 An error value, such as #N/A 
          64 An array of values 
          
          You can use the sum of the allowable values for Type. For example, for an input box that 
          can accept both text and numbers, set Type to 1 + 2.

          Steve

        • #982182

          From the Excel Help file:

          [indent]


          Type Optional Variant. Specifies the return data type. If this argument is omitted, the dialog box returns text. Can be one or a sum of the following values.

          Value Meaning
          0 A formula
          1 A number
          2 Text (a string)
          4 A logical value (True or False)
          8 A cell reference, as a Range object
          16 An error value, such as #N/A
          64 An array of values


          [/indent]

    • #982179

      Instead of macro, if you are using goto to goto a location, you could chose “selection” in the “Print what” part of the print dialog.

      Steve

      • #982183

        Steve, I had been doing that but it seemed to involve more steps than what I am used in QuattroPro. Legare’s macro fills the bill perfectly. Thanks!

        Steve and Legare, thanks for the information. Someday I’ll have to sit down and actually learn some basic VBA. I appreciate being able to pick your brains until I do this.

    Viewing 1 reply thread
    Reply To: Macro to Select & Print Selection (XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: