+ Reply to Thread
Results 1 to 9 of 9

PrintSelectionToPDF - Select an area in sheet based on "Selected" - divided into 2 pages

  1. #1
    Registered User
    Join Date
    09-02-2021
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    4

    PrintSelectionToPDF - Select an area in sheet based on "Selected" - divided into 2 pages

    I have written this, but have a problem that if one of the ranges are "False", then the print is divided into two printed pages. Can anyone see what the problem is?

    Sub PrintSelectionToPDF()
    Dim UruruSelected As Boolean, PerferaSelected As Boolean, StylishSelected As Boolean, EmuraSelected As Boolean, GulvSelected As Boolean
    If Sheets("Indtast her").Range("F5").Value = "Ja" Then UruruSelected = True
    If Sheets("Indtast her").Range("F9").Value = "Ja" Then PerferaSelected = True
    If Sheets("Indtast her").Range("F13").Value = "Ja" Then StylishSelected = True
    If Sheets("Indtast her").Range("F17").Value = "Ja" Then EmuraSelected = True
    If Sheets("Indtast her").Range("F21").Value = "Ja" Then GulvSelected = True
    Sheets("Prislisteudvalg").Select
    Dim Headline As Range, Ururu As Range, Perfera As Range, Stylish As Range, Emura As Range, Gulv As Range, Bund As Range
    Dim pdfile As String
    'Setting range to be printed
    Set Headline = Range("A1:I3")
    Set Ururu = Range("A4:I7")
    Set Perfera = Range("A8:I11")
    Set Stylish = Range("A12:I15")
    Set Emura = Range("A16:I19")
    Set Gulv = Range("A20:I23")
    Set Bund = Range("A24:I36") '
    'Set myMultipleRange = Union(Headline, Ururu, Perfera, Stylish, Emura, Gulv, Bund)
    Set myMultipleRange = Headline
    If UruruSelected Then
    Set myMultipleRange = Union(myMultipleRange, Ururu)
    End If
    If PerferaSelected Then
    Set myMultipleRange = Union(myMultipleRange, Perfera)
    End If
    If StylishSelected Then
    Set myMultipleRange = Union(myMultipleRange, Stylish)
    End If
    If EmuraSelected Then
    Set myMultipleRange = Union(myMultipleRange, Emura)
    End If
    If GulvSelected Then
    Set myMultipleRange = Union(myMultipleRange, Gulv)
    End If
    Set myMultipleRange = Union(myMultipleRange, Bund)
    'setting file name with a time stamp.
    pdfile = "Prisliste" & "_" & Format(Now(), "yyyymmdd_hhmmss") & ".pdf"
    'setting the fulli qualified name. The resultent pdf will be saved where the main file exists.
    pdfile = ThisWorkbook.Path & strfile
    myMultipleRange.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=pdfile, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=True
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: PrintSelectionToPDF - Select an area in sheet based on "Selected" - divided into 2 pag

    Why haven't you placed the code in your attachment?
    Please read the forum rules for posting code
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: PrintSelectionToPDF - Select an area in sheet based on "Selected" - divided into 2 pag

    Sorry, saw the code in the worksheet module.
    You also have a problem with the pdfile name you define it but don't use it, you use strfile instead,
    I don't see any relation to both worksheets except that you create a multi sheet but what are you doing with it?
    My Danish is no good but I'll have to look at what you're doing, and hard coding sections like you do is very bad when it comes to making changes

  4. #4
    Registered User
    Join Date
    09-02-2021
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    4

    Re: PrintSelectionToPDF - Select an area in sheet based on "Selected" - divided into 2 pag

    Hi
    Thanks for your input - but can you see why it makes the pagebreak?

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: PrintSelectionToPDF - Select an area in sheet based on "Selected" - divided into 2 pag

    YOU are adding the page breaks with every Nej

  6. #6
    Registered User
    Join Date
    09-02-2021
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    4

    Re: PrintSelectionToPDF - Select an area in sheet based on "Selected" - divided into 2 pag

    I am really new to this - so can you explain where in the code I specify that "Nej" means page break?

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: PrintSelectionToPDF - Select an area in sheet based on "Selected" - divided into 2 pag

    I haven’t had the time het but It’s your code.
    You check for Ja and the other option Nej or whatever is what triggers the page break
    I do not even know or see how you fill the worksheet that is to be exported as pdf

  8. #8
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413
    Quote Originally Posted by KatheR View Post
    Hi
    Thanks for your input - but can you see why it makes the pagebreak?
    I will have a look later if your problem isn't solved, I understand Danish 😊

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: PrintSelectionToPDF - Select an area in sheet based on "Selected" - divided into 2 pag

    Try this one, I'll explain it tomorrow
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Formula to add a "yes" or "no" based on checkboxes being selected?
    By Gootz in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-30-2017, 12:44 PM
  2. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  3. Replies: 1
    Last Post: 07-16-2016, 09:20 PM
  4. [SOLVED] Code that copies row of data to another sheet based on text "Complete"/"Delete"
    By Dremzy in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 04-20-2014, 05:51 PM
  5. Modify code to email a selected range or ("print area") in lieu of ActiveSheet
    By robertse in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-15-2010, 05:15 PM
  6. Remove all "to " from selected area
    By wali in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2010, 09:10 AM
  7. Questionnaire sheet: Select "yes" or "no," and only one can be selected
    By bpatterson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-13-2006, 06:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1