Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Macro for Printing/ Preview in VBA

This is a discussion on Macro for Printing/ Preview in VBA within the Excel Questions forums, part of the Question Forums category; Hi once again. On the verge of ending this project and you guys have been awesome in helping me... I ...

  1. #1
    New Member
    Join Date
    Dec 2010
    Posts
    30

    Default Macro for Printing/ Preview in VBA

    Hi once again. On the verge of ending this project and you guys have been awesome in helping me... I hope this is the last hurdle... Ok here I go

    When I hit the "Show DataBase" button, I want a print preview of "Supplier Database" in excel.

    What I did was, record a macro, and simply call in that button. When I hit the button, it shows the preview, but the problem is somehow, the program gets into some loop... I cannot break it or stop it... I have to use CRTL+ALT+DEL method to close entire excel to break the loop...

    Any Idea whats happening and how it can be stopped ?

  2. #2
    Board Regular dave3009's Avatar
    Join Date
    Jun 2006
    Location
    Glasgow, Scotland
    Posts
    6,291

    Default Re: Macro for Printing/ Preview in VBA

    I used this

    Code:
    Private Sub CommandButton1_Click()
    Me.PrintPreview
    End Sub
    I didn't get any looping issues, you can change Me to Sheets("Supplier Database").

    If this doesn't work then perhaps post the actual code you're using.
    Please state your version of Excel, I use Excel 2007 on Win 7.
    Back up all data before testing VBA codes, and please use [code] tags.
    davehouston.co.uk/

  3. #3
    New Member
    Join Date
    Dec 2010
    Posts
    30

    Default Re: Macro for Printing/ Preview in VBA

    I tried that as well... it is again acting the same way... unlimited loop or something

  4. #4
    Board Regular dave3009's Avatar
    Join Date
    Jun 2006
    Location
    Glasgow, Scotland
    Posts
    6,291

    Default Re: Macro for Printing/ Preview in VBA

    Well something must be causing it, but I don't see any codes or a copy of the workbook so that I might reasonably be able to use to assist you further
    Please state your version of Excel, I use Excel 2007 on Win 7.
    Back up all data before testing VBA codes, and please use [code] tags.
    davehouston.co.uk/

  5. #5
    New Member
    Join Date
    Dec 2010
    Posts
    30

    Default Re: Macro for Printing/ Preview in VBA

    the code is

    HTML Code:
    Private Sub cmdDBase_Click()
    
    Worksheet("Suppliers").Activate
    
    Worksheet("Suppliers").PrintPreview
    
    End Sub

  6. #6
    Board Regular dave3009's Avatar
    Join Date
    Jun 2006
    Location
    Glasgow, Scotland
    Posts
    6,291

    Default Re: Macro for Printing/ Preview in VBA

    And do you have any Worksheet Activate event codes in the book?

    What happens if you just try

    Code:
    Private Sub cmdDBase_Click()
    
    Worksheet("Suppliers").PrintPreview
    
    End Sub
    Please state your version of Excel, I use Excel 2007 on Win 7.
    Back up all data before testing VBA codes, and please use [code] tags.
    davehouston.co.uk/

  7. #7
    New Member
    Join Date
    Dec 2010
    Posts
    30

    Default Re: Macro for Printing/ Preview in VBA

    No not in this procedure... this procedure is as much as I posted...

    See the entire Program is quite big... It takes input, saves in excel, generates new sheets, fill them etc etc.... But every procedure is used in different form... this particular form has only one button that has to show the preview of the database...Does working in Excel 2003 and 2007 make any difference coz I am rite now in 2003

  8. #8
    Board Regular dave3009's Avatar
    Join Date
    Jun 2006
    Location
    Glasgow, Scotland
    Posts
    6,291

    Default Re: Macro for Printing/ Preview in VBA

    It shouldn't, have you any Workbook Before Print event codes?
    Please state your version of Excel, I use Excel 2007 on Win 7.
    Back up all data before testing VBA codes, and please use [code] tags.
    davehouston.co.uk/

  9. #9
    New Member
    Join Date
    Dec 2010
    Posts
    30

    Default Re: Macro for Printing/ Preview in VBA

    Honestly I did not understand that question... But this is the first sheet of the workbook and no other workbooks are active when this is working...if that is what you wanted to know

  10. #10
    Board Regular dave3009's Avatar
    Join Date
    Jun 2006
    Location
    Glasgow, Scotland
    Posts
    6,291

    Default Re: Macro for Printing/ Preview in VBA

    You're using a userform here right?

    Try

    Code:
    Private Sub cmdDBase_Click()
    
    Unload Me
    
    Worksheet("Suppliers").PrintPreview
    
    End Sub
    Please state your version of Excel, I use Excel 2007 on Win 7.
    Back up all data before testing VBA codes, and please use [code] tags.
    davehouston.co.uk/

Page 1 of 2 12 LastLast

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com