+ Reply to Thread
Results 1 to 3 of 3

Problem with Print Preview

  1. #1
    Registered User
    Join Date
    05-23-2005
    Location
    Belgium
    Posts
    2

    Problem with Print Preview

    I 've made a VBA prog that generates a print preview from 3 different sheets. it selects the not empty sheets and gives the preview.
    When i want to close the preview excel bails out with an error, unless the preview shows the first sheet. Already tried to change the order in the selection, without any effect.
    Does anybody know why this happens?


    this is my code so far:


    Private Sub cmdAfdrukkenLijsten_Click()

    Dim intRij As Integer

    'adding some extra cells before printing (if sheets aren't empty)

    If Worksheets("luchtgroepen").Range("B5") <> "" Then
    Call legende
    Worksheets("luchtgroepen").Select
    intRij = Worksheets("luchtgroepen").Range("A1").Value
    Worksheets("luchtgroepen").Range("A" & intRij).Select
    ActiveSheet.Paste
    Range("A" & intRij, "B" & intRij).Font.Bold = True
    End If

    If Worksheets("specifiek klant").Range("B3") <> "" Then
    Call legende
    Worksheets("specifiek klant").Select
    intRij = Worksheets("specifiek klant").Range("A1").Value
    Worksheets("specifiek klant").Range("A" & intRij).Select
    ActiveSheet.Paste
    Range("A" & intRij, "B" & intRij).Font.Bold = True
    End If

    'determening print-area

    Worksheets("overzichtsblad").Activate
    intRij = Worksheets("overzichtsblad").Range("A1").Value + 2
    ActiveSheet.PageSetup.PrintArea = "$A$1:$J$" & intRij

    'selecting non-empty sheets foor preview

    If Sheets("specifiek klant").Range("B3") <> "" Then
    If Sheets("luchtgroepen").Range("B5") <> "" Then
    Sheets(Array("overzichtsblad", "specifiek klant", "luchtgroepen")).Select


    Else
    Sheets(Array("overzichtsblad", "specifiek klant")).Select

    End If
    Else

    If Sheets("luchtgroepen").Range("B5") <> "" Then
    Sheets(Array("overzichtsblad", "luchtgroepen")).Select

    Else
    MsgBox "Geef eerst de onderdelen van de installatie op." & vbCrLf & _
    "Voor uitleg klik op de Info knop", vbOKOnly + vbExclamation, "Fout"
    Exit Sub

    End If

    End If

    ActiveWindow.SelectedSheets.PrintPreview

    End Sub

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning Nico-VDB

    You are not trying to open the print preview screen over the top of a dialog box that is already open are you? It's just that I have had tht exact problem, and the only solution I could find was to remove the box before calling the print preview. I also found that the print preview screen is not like a normal XL window and problems can arise of you are trying to close the preview window within your module, so that you can run a piece of code after the preview.

    HTH

    DominicB

  3. #3
    Registered User
    Join Date
    05-23-2005
    Location
    Belgium
    Posts
    2
    The code that is posted above is writen on the event click for a command button located on a sheet that isn't included in the print preview. There are no forms or dialog boxes loaded.
    Or does excel load dialog boxes on startup...? (i m rather new in this...)

    the posted code is called only with a click on the button. And as you can see the preview is called as last line before the end sub.

    i ve tried splitting the array of sheets into different previews. It works when i do so, but my pagenumbers are screwed up by doing so. Also it gives 3 separated previews, i 'd rather have just 1 preview that includes everything at once... (easy solution won't do... )

    Quote Originally Posted by dominicb
    Good morning Nico-VDB

    You are not trying to open the print preview screen over the top of a dialog box that is already open are you? It's just that I have had tht exact problem, and the only solution I could find was to remove the box before calling the print preview. I also found that the print preview screen is not like a normal XL window and problems can arise of you are trying to close the preview window within your module, so that you can run a piece of code after the preview.

    HTH

    DominicB

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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