Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. However, I only want this code to fire when the user is actually printing, not when they are just calling the print preview.
The code cancels the event and then prompts the user, based on their response it displays the print preview or prints. I think I would provide a very visible button for the user to push when wanting to Print Preview. Each one would would require a different button, but either way I would strongly suggest testing if you really need both, because the preview button may work for your print option, especially since you would in most cases be able to print straight from the preview.
Outstanding Ways To Create Print Command Button in Excel
Learn more. Difference between print and print preview events in excel vba Ask Question. Asked 10 years, 7 months ago. Active 3 months ago. Viewed 19k times. Active Oldest Votes. I don't think there is a neat way to determine if the event is a print preview or print request. The solution below is not particularly neat and inconveniences the user slightly, but it works. PrintPreview Else ActiveWindow. PrintOut End If Application. Robert Mearns Robert Mearns Make the button hide for printing in the options for the buttonand have the code simply say: ActiveWindow.
Siddharth Rout k 16 16 gold badges silver badges bronze badges. To print you could do something like this: ActiveWindow. PrintPreview Each one would would require a different button, but either way I would strongly suggest testing if you really need both, because the preview button may work for your print option, especially since you would in most cases be able to print straight from the preview. I may be wrong here, but I don't think so.
Enjoy :. Matt Ridge Matt Ridge 3, 14 14 gold badges 41 41 silver badges 59 59 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Socializing with co-workers while social distancing. Podcast Programming tutorials can be a real drag. Featured on Meta. Community and Moderator guidelines for escalating issues via new response….
Feedback on Q2 Community Roadmap. Dark Mode Beta - help us root out low-contrast and un-converted bits. Technical site integration observational experiment live on Stack Overflow.Keep in touch and stay productive with Teams and Officeeven when you're working remotely.
Learn how to collaborate with Office Tech support scams are an industry-wide issue where scammers trick you into paying for unnecessary technical support services.
You can help protect yourself from scammers by verifying that the contact is a Microsoft Agent or Microsoft Employee and that the phone number is an official Microsoft global customer service number. In the Now in the box immediately below scroll down to Click on Click that Did this solve your problem? Yes No. Sorry this didn't help. Add r. Left, r. Top, r. Width, r. Excel deals in workbooks and worksheets with possibly multiple print ranges on each worksheet. What exactly will you be printing?
Entire workbook? One or several worksheets? Ranges from worksheets? User selections? April 14, Keep in touch and stay productive with Teams and Officeeven when you're working remotely.
Site Feedback. Tell us about your experience with our site. Shah Alam Created on January 26, Dear Expert, How can I put a 'print' button on excel sheet to get my docs printed immediately. This thread is locked. You can follow the question or vote as helpful, but you cannot reply to this thread.
I have the same question Volunteer Moderator. Thanks for marking this as the answer. How satisfied are you with this reply? Thanks for your feedback, it helps us improve the site.Forums New posts Search forums. What's new New posts New Excel articles Latest activity. New posts. Excel Articles Latest reviews Search Excel articles. Log in Register. Search titles only. Search Advanced search…. Search forums.
Subscribe to RSS
Disabled command buttons on Print Preview Screen. Thread starter DerekD Start date Oct 29, DerekD New Member. Joined Oct 29, Messages 1. I have created a small database application using Excel in which the user does not have direct access to any of the worksheets.
Some videos you may like. Excel Facts. Bring active cell back into view. Click here to reveal answer.
Start at A1 and select to A while writing a formula, you can't see A1 anymore. You must log in or register to reply here. Watch MrExcel Video. Forum statistics Threads 1, Messages 5, MembersLatest member alkin.
The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.
Occasionally, I'll happen across a spreadsheet which suffers from magic buttons or listboxes which get bigger or smaller over time. The problem seems to relate to the way Windows handles non-native resolutions on monitors and can be avoided in several ways. We have been testing recently an excel worksheet used by a few dozen people and have developed a good idea of the cause and some possible fixes. The cause seems to relate to any setup where screens are used in something other than their native resolution.
This can happen easily if a user plugs an external monitor into a laptop and doesn't choose the resulting screen configuration carefully. For example, if a laptop is plugged into a projector perhaps an old one with a native by display but the laptop is a by and the user chooses to duplicate the display rather than extending it settings in "connect to a projector" or "displays" control panel in Windows 7the result is an unpredictable and usually unsatisfactory image on both screens with both in non-native resolutions.
We have found that these settings almost always cause serious problems with Excel buttons, especially ActiveX controls. Sometimes, on repeated clicks, they shrink to unreadability; other times they expand to cover the whole screen. Mostly, when we instruct users to use the extend display setting and the result is two screens both using native resolutions, we don't see the problem. There are also code-based ways to minimize the problem. We tried resetting the location and size of buttons and controls when they were clicked which adds a lot of tedious code if you have a lot of buttons.
This sometimes worked. We also tried toggling the autosize property from true to false and back this works manually in developer mode and this fixes more instances, but not apparently all. This affects the controls available from the control toolbox, but yet to experience the issue using an old school forms button control, so my unsatisfactory answer is to use that. This has been plaguing me for years, on and off.
There are a number of fixes around, but they seem hit and miss. It was still occurring in Excel happening to me Mayand is still occurring in Excel by some reports. This problem is in fact due to screen resolution. Most commonly it occurs when the user connects to a projector, or WebEx while using the excel application.
A simple solution to this problem is to ask the user to reboot their machine without any peripheral connections projector and then open the excel application again. My monitors all appear to be set at native resolutions, which deepens the mystery. This routine automates the moving, and then restores the original setting.
This problem is very frustrating, my experience is that the properties are usually set properly on the ActiveX objects.
I've modified a UDF from above to just be able to run on any active sheet, this will set everything back the way it was before shrinking.
I noticed that none of these answers anchor the control to a specific row and column. In the below example, the button will always snap to covering D8:FForums New posts Search forums.
This has got to be the weirdest thing I've seen happen yet I have a workbook with several sheets in it, and about 10 different buttons I've created on each sheet.
The following problem happens when I select more than one sheet and choose Print Preview: If I close the print preview, or print from the preview, from any page except the first visible one, when I return to the normal view of the workbook all of the buttons I've created are distorted, stretched and way out of position! Looking at it the other way, if I exit Print Preview, or Print from the Preview, from the page that I first see when going into the Print Preview, everything is just fine- no button problems at all.
It's only when it's from a page that's not the first one I see first when going to the Preview! All of the button's format controls are set to 'Move but don't size with cells' and they are set to NOT print. Also, the more pages in the workbook I have and the further away I close or Print from the first visible page in Preview, the worse the distortion and displacement is! Does anyone have any idea why this is happening, seen this before, or know how to fix it?Lbound ubound.
Do loop. For next. If then else elseif end if. Select case. With end with. Array variables. Combo boxes. Dialog boxes. Like operator. List boxes. Text boxes. Copy from workbooks. Non-contiguous rngs. Select blank cells. Quick access toolbar. Run macro when open. How to - Dialog boxes. Consecutive values. List comments [VBA]. Copy filtered tables. Add macro to ribbon. Toggle hidden sheets. Toggle hidden column.
Scroll bar. Count cell color. Date ranges overlap. Count text string in all formulas in a worksheet [VBA]. Locate a shape in a workbook. Change a pic. Move a shape [VBA].So the moment we select this print option you can see there is different settings which are available here and also there is preview that is available for the print option. Let us look at page 2. Page 2 only contains some incomplete information regarding the regarding the earlier set of table that we had. Now let us look at what is page 3.
So probably this is the preview if we are to print this worksheet this is how we will get in terms of the print out.
Create A Print Command Button
So probably you may not like this at this stage. So we have to kind of do some adjustments here and there so that when we take a print out it looks really professional.
So let us look at various print options in much detail. On top you will find this is the print icon and to select the number of copies you want to print you can adjust it from here.
So let say if I want 5 copies I can select 5 here or you can mechanically type 15 copies or 10 copies, 1 copy or 2 copies as such. So let me keep it itself. If your printer is online it will show online or else you may to kind of select your printer which one is ready so say for example here, this printer is ready for use. So the moment I give the print it will print the pages which I am looking at in the worksheets.
Now there are other set of settings which are available so one of the settings are print active sheets. If you see in the drop down there are various options print active sheets and that is what I want and do you want to print an entire workbook from sheet 1 sheet 2 sheet 3 and sheet 4. Do you have any selection for printing? There are various options which you can look at for printing.
For the time being I am just keeping it as print active sheets. Now the other option that you can see is that if you have to print only selective page let say page 1 and page 2. So in this worksheet as you may have noted that there are three pages, they are 1, 2 and 3 and I just want to print only 2 pages.
So page me and page 2 or page 1 to page 1 so this will print only the first page so you can also look at these set of options. So for the time being let me have page 1 to page 3. What will this collated means?