I have a before print event that shows a userform - the user can then select which worksheets they want printed and select a command button. I then have a loop set up that loops through the selected workbooks and prints them. The problem is I am not sure how to tell VBA to print without it going back to the Before Print event userform.
This is weird - if you delete a sheet that contained a control then
a. showing a modeless userform resluts in a userofrm that goes invisible at subroutine End b. public variables lose their value
These things do not happen if the sheet did not contain a control. Attached is an example file - put the inputfile.xls in your default file location (or add a path in the code) then open the ProblemDemo.xls and run the main macro to see it fal - isthis another Excelbug I've found?
I have a WYSIWYG problem: what I see on the screen is NOT what I get out of the print job.
I commonly have the problem when working with Excel objects (any kind of shape, text box, line, graph) in that the layout looks great on the tab that I created, but when I go into PrintPreview or actually print it out, the shapes don't quite align with what I had built in the tab. Where I thought I had lines joining, the print out shows them crossing at other points. If I then go back to the tab and look at the layout on the regular screen, it looks fine.
This problem can be easily understood if you try to create a triangle by drawing three lines (non-overlapping lines that cross only at the vertices). Note that the lines either prematurely cross, or don't intersect at all when you print it out.
THis problem is even magnified when using the camera function to take a "snapshot" of a graph or other objects. In fact, it has the tendency to even "mess up" the graph's formatting, regarding the arrangement of titles and axes (often making them overlap).
When I view my page on print preview it shows 2 pages but I only have stuff on one page the second page shows 2 border marks but when I go to erase them I can't find them. Is there some way that I can find them other than look at page after blank page.
I created a Userform on top of an excel files. The userform uses data contained in the excel file. When my users open this file, I would like them to only see the userform and not the excel file in the background. I have tried the following but it prevents the userform from working.
Private Sub Workbook_Open() ThisWorkbook.Windows(1).Visible = False UserForm1.Show End Sub
Private Sub Workbook_Open() Application.Visible = False UserForm1.Show End Sub
I am attempting to show a User Form during the forms Initialize code. I Load the form after extracting data from a SQL Server database. The code that Loads the form is returned to after the form closes. The problem is that when I run through the Initialize code where criteria decides whether the form is actually shown to the user. If the criteria is not met there are no issue, but if the criteria is met, then the form is opened and the rest of the Initialize code is not stepped through. As there are many If Then and a Select Case and a couple With...'s I need the rest of the Initialized code to be stepped through so after the form is closed by the user and the original code which Loaded the form is returned to I do not get an error.
Oh and the big problem is that I am not getting an error message during this, the Load code is actually repeated because when the original code is actually returned to is returned on the Load UserForm code.
Private Sub UserForm_Initialize() Dim i As Integer, Endofdata As Integer, wsheet3 As Worksheet, wbBook As Workbook Dim wsSheet As Worksheet, c As Variant, gTotal As Long, Score As String, g3000 As Long Dim gTotalAdd As Integer
On Error Goto ErrorHandler: Application. ScreenUpdating = False 'cmbIDCountry.ColumnCount = 2 Set wbBook = ThisWorkbook Set wsheet3 = wbBook.Worksheets("UpdateDetails") Set wsSheet = wbBook.Worksheets("Data") ....................
I have a Word document that I'd like to print first, when I click Print on a specific worksheet (not on Print of other worksheets in the workbook, just the one). The worksheet contains customer information and is essentially a cover page for the Word document. the Word document already prints in reverse order, as does the worksheet, so I just need the Word doc to print prior to the worksheet/cover, to give me the total print package in the correct order. I've tried using the following code in the Sheet object for the worksheet in question;
Private Sub Worksheet_BeforePrintEvent() Dim appWd As Word.Application Set appWd = CreateObject("Word.Application") appWd.Visible = True 'Change to False when code is good 'Open Doc appWd.Documents.Open Filename:="S:BryanQuoting ToolsP'Binder Leading Pages.doc" 'Print Doc appWd.ActiveDocument.PrintPreview 'Change to PrintOut when code is good 'Close Doc Set appWd = Nothing End Sub
with an event macro. Basically I have a workbook with 11 worksheets and have created a macro that increases the value of cell J3 by 1 in Sheet1. However at present it only works from Sheet5, but I now need it to run from Sheet6 and Sheet11 as well and not from any other worksheets. The code I have is as follows
Private Sub Workbook_BeforePrint(Cancel As Boolean) If ActiveSheet.CodeName = "Sheet5" Then With Sheet1 .Range("J3").Value = .Range("J3").Value + 1 End With End If End Sub
I have a project report, which is user-configurable, allowing the user to customise the data that is displayed based on a number of parameters.
To ensure the report always prints neatly (the number of visible columns and rows varies, depending on the above parameters), so I have a macro that dynamically sets the print area of the worksheet.
At present, I call the macro from the workbook.beforeprint event, which works fine in terms of printing. Ideally however, I would like the macro to be called when CTRL+P is first pressed - i.e. the resulting 'print screen', containing a preview of the print out should reflect what will subsequently be printed, when the 'Print' button is then pressed.
I am not sure if this makes sense (Excel 2010 and 2013 are different from previous versions).
=OFFSET(Sheet1!$A$1,0,0,MATCH("PRINT_AREA_ROWS",Sheet1!$A:$A,0),MATCH("PRINT_AREA_COLUMNS",Sheet1!$1:$1,0)), lets say this equates to range("A1:D12")
I also have a workbook beforeprint event defined as follows:-
Private Sub Workbook_BeforePrint(Cancel As Boolean) ActiveSheet.PageSetup.LeftFooter = "Pete" End Sub
My problem is that after the Print Event has fired , the dynamic range has been converted into a static one i.e range("A1:D12"). I have tried this on all version of Excel from 97 to 2007 and it behaves the same so premably this must be by design rather than a bug?
Am I doing something wrong? What is the work around? I'd rather not have to create the dynamic range within the print event procedure unless I have to as my workbook has many, many tabs!
Is there an event that fires every time anything is clicked within a userform? I have seen the userform_Click() event however, this only works if the userform is clicked directly and not if something like an image is clicked on top of it.
The use of this userform is to find a customer reference number. Im using two combobox's and a textbox.value that are populated from another workbook.
Though the way it is at the moment it opens the workbook and closes the workbook every time a new value is set to one of the combobox's.
I want to open the workbook on the useform initialize and do everthink the useform need from it. And then on the userform terminate close the workbook. Or somehink to this equlivent so this process of finding the customer referance number goes faster.
I create a series of labels and text boxes at runtime.
Code: for x = 1 to 10 labelName = "label" & x Set cControlLabel = Me.frameScrollable.Controls.Add("Forms.Label.1", labelName, True) next x
How can I assign an on_click event to these? I have seen some rather complicated suggestions such as creating code for each possible object, but there could possibly be hundreds of labels created. It would be nice to be able to call the same macro from each label click, and then take action based on the .caption property of the label.
I have a userform where I have 2 comboboxes. The first combobox shows the the first column (only 1 of each) and the second comboBox shows me the secondary list that correlates to the valuse in the first from column B. Now I have a text box that I am trying to get the value from column C depending on what I have in the first 2 comboboxes. What is the easiest way to do it? This is all in VB since it is a UserForm, and using Vlookup seems to be too many lines if I go that route. Is there a way to use Index and Match in VB where it would be more efficient? I attached just a sample of how the data would be layed out in the Excel sheet.
I have this code, which does what i want it to do but i want 5 userforms printed in a4 and 1 in a3, also i want to print them all in colour, as they contain graphs, and visually its poor when in black and white
I added in black and white = false, but it still prints black and white, i tried size = A3 and that wouldnt work either
I have a number defined print ranges. I wish to create a list of all the named print ranges and then select certain ranges to print in a single document. I have been told can use something called a "userform".
with printing a long userform? Unfortunately, the me.printform does not print out the whole form. It gets cut off because my form is too long and slightly too wide. I also tried to do a print screen, but unfortunately, because my form is too long, it will only do a snapshot of a portion of the form. In my case, on the bottom as that is where I have placed my command button.
Does anyone know how to bring the whole form out to excel or word? I don't mind doing that as long as I can print out the whole form?
On my excel 2007 UserForm I have a CheckBox with 18 possible or multiple selections of reports (word.docm) what I would like to do is, when selected they would be sent to printer.
Here's what code I have so far, something is missing, I'm not sure
Private Sub CommandButton2_Click() For x = 1 To 18 If Controls("checkbox" & x) Then Select Case x Case x = 1 worddoc = ActiveWorkbook.Path & "Inspection ReportsCover Page.docx" Case x = 2 worddoc = ActiveWorkbook.Path & "Inspection ReportsClient Information.docx" Case x = 3.....................
I have developed an extensive program running on excell but with the user only seeing userforms. I would now like to build in a "print screen" button, but have no idea how to do this.
What it needs to do is capture the userform and all its entries (as it is displayed on the screen) and send this to the printer to be printed as a picture. I am assuming that there must be code available so that when ever the user clicks this button, the standard windows (or excell) print screen appears from which he will be able to choose the printer etc.