Macro for Printing/ Preview in VBA

mars07

New Member
Joined
Dec 28, 2010
Messages
30
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 ?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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.
 
Upvote 0
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
 
Upvote 0
the code is

HTML:
Private Sub cmdDBase_Click()

Worksheet("Suppliers").Activate

Worksheet("Suppliers").PrintPreview

End Sub
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
It shouldn't, have you any Workbook Before Print event codes?
 
Upvote 0
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
 
Upvote 0
You're using a userform here right?

Try

Code:
Private Sub cmdDBase_Click()

Unload Me

Worksheet("Suppliers").PrintPreview

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,988
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top