Simple Question - VBA to Print Multiple Sheets`

UNC_Access

Registered User.
Local time
Yesterday, 19:28
Joined
Oct 24, 2012
Messages
42
Hi!

Here is my goal:

Print sheets "01" and "01A" when the ActiveSheet is sheet "01".

Here is my code:

Code:
Sub Print_Sheets()
   Dim x As String
   x = ActiveSheet.Name
   Sheets(Array(x, [COLOR=Red]x&"A"[/COLOR])).PrintOut
End Sub
I'm getting an error on the red part.

The key is that I need to print out 2 sheets, "_" and "_A" (concatenated with "A" at the end).

Any ideas?
 
I would try concatenating before the array line...
 
Why the Array? Why not two simple Print commands?

Brian
 
This is what I think will be useful.
Call this Sub - in add a sub string as the argument - it will print all worksheets in the workbook that contain the entered string:

SheetPrintU "AA" ' prints all worksheets with AA anywhere in the name

Code:
Sub SheetPrintU(WhatsAMatterU As String)
Dim AWorkSheet As Worksheet
  Dim i As Integer
      For i = 1 To ActiveWorkbook.Worksheets.Count
        Debug.Print Worksheets(i).Name & " in list - will it be printed?"
        If Worksheets(i).Name Like "*" & WhatsAMatterU & "*" Then
            'Worksheets(i).PrintOut ' uncomment and add more print code here for landscape, borders, etc
          Debug.Print Worksheets(i).Name & "  This worksheet Meets criteria of input argument and could be printed out"
        End If
      Next i
End Sub

Some other code for printing
Sub PrintMeOneAtATime
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
Sheets("01A").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
Sheets("01").Select
End Sub

Printing first 2 Worksheets for example
Sub PrintUsingArray()
Dim iSheetU As Integer
On Error Goto DOH
For iSheetU = 1 To 2 ' Will error if there are not enough worksheets
With Sheets(iSheetU )
.PrintOut
End With
Next
DOH:
End Sub
 

Users who are viewing this thread

Back
Top Bottom