Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Excel: Define front for sheet 1 and back for sheet 2

Hello experts,

I have the attached document related to my shortcuts.
I was wondering how to:
1-Set up print zone and define front related to sheet 1 and back related to sheet 2
So the result will be two sheets in a the same doc.

This will allows me to have in a single doc if I generate a pdf or if I print document sheet 1 and sheet 2.
If you have questions, please contact me.
Thank you for your help.
1-Key-shortcuts-LDI.xlsx
Avatar of Kanwaljit Singh Dhunna
Kanwaljit Singh Dhunna
Flag of India image

Avatar of Luis Diaz

ASKER

Thank you but it doesn't reply to the need. which is to create a single front and back pages pdf based on two sheets.
I found a solution which is to to export the various sheets into a single pdf file.
I was wondering if someone can help me to adjust the following:

Sub Export_Sheets_One_Pdf()
    Dim FolderPath As String
    
    FolderPath = ActiveWorkbook.Path
    
    Sheets(Array("1", "2")).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FolderPath & "\Export" & "_" & Format(Now, "yyyymmddhhmmss"), _
        openafterpublish:=False, ignoreprintareas:=False
    

End Sub

Open in new window



With the following requirements:
-Instead of selecting the various sheets i.e. : Sheets(Array("1", "2")).Select I need to loop into the various sheets of activeworkbook
-Open exported folder Shell "C:\WINDOWS\explorer.exe """ & FolderPath & "", vbNormalFocus
If you  have questions, please contact me.
ASKER CERTIFIED SOLUTION
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much for this proposal. It works.
Possible to have a last version to exclude specific sheet by name (E.g name: Instruction) in loop:
 ActiveWorkbook.Worksheets(1).Select
    For i = 2 To ActiveWorkbook.Worksheets.Count
        ActiveWorkbook.Worksheets(i).Select False
    Next

Open in new window

Thank you for your help.
Added another variable (bFirst), so here is the complete routine:
Sub Export_Sheets_One_Pdf()
    Dim FolderPath As String
    Dim i As Integer
    Dim pid As Long
    Dim bFirst As Boolean
    
    FolderPath = ActiveWorkbook.Path
    bFirst = True

    For i = 1 To ActiveWorkbook.Worksheets.Count
        If ActiveWorkbook.Worksheets(i).Name <> "Instruction" Then
            If bFirst Then
                bFirst = False
                ActiveWorkbook.Worksheets(i).Select
            Else
                ActiveWorkbook.Worksheets(i).Select False
            End If
        End If
    Next
    
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FolderPath & "\Export" & "_" & Format(Now, "yyyymmddhhmmss"), _
        openafterpublish:=False, ignoreprintareas:=False
    
    cmd = "C:\WINDOWS\explorer.exe """ & FolderPath & """"
    
    pid = Shell(cmd, vbNormalFocus)

End Sub

Open in new window

Thank you.
Just for my knowledge. Why not putting bfirst=false at the end first if condition. Line 14 and not at the beginning?
Are you asking why I don't switch around lines 13 and 14?
It makes no difference  ... it would have the same effect.
Noted. Unable to test it right now. I will keep you informed.
Tested and it works.
Thank you for your help.
You are most welcome.