|
Print All Charts That are in a Worksheet
This macro will print all of the embedded charts which are on the current active worksheet. Each chart will be printed on a separate page.
Where to install the macro: Module
Print All Embedded Charts in a Worksheet
Sub PrintEmbeddedChartsinWORKSHEET()
'Prints all embedded worksheets that are on the active worksheet '
Dim ChartList As Integer
Dim X As Integer
ChartList = ActiveSheet.ChartObjects.Count
For X = 1 To ChartList
ActiveSheet.ChartObjects(X).Select
ActiveSheet.ChartObjects(X).Activate
ActiveChart.PrintOut Copies:=1
Next
End Sub
How to Install the Macro
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007 Go to Tools > Macros > Visual Basic Editor
For Excel 2007 Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 8.
- Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.
- You are now ready to run the macro.
Similar Helpful Excel Resources
All for the same file
a.) I have an invoice template in one excel file in which I fill in data, out of which some of it auto fills as it is linked to another excel file in which the master data is stored and updated. I wish to edit this invoice "template" (if u may call it that) and once I am done, I wish to click on the Print Macro enabled button that will print 2 copies. (i) 1st Copy with "Customer Copy" and (ii) 2nd Copy with "Merchant Copy" inserted at the bottom
b.)Then I would like to have another Macro enabled button which would:
-Save existing open Worksheet(which has just been printed) as a new Excel file with only the values (no Formalae nor Linking) , retain the exact formatting in the new file (column width etc.), and derive the filename from a cell value from the existing open sheet(edited template) [which will not be present in the new file as it will be out of print area] (the cell is on the far right on the sheet), Close the new file created to a designated folder, and keep the "template" open. Template should be open with the last edited info in order to key in the next chronological invoice no. (Don't know how to automate Invoice Numbers in this scenario, incrementation of the Invoice no. upon the event of Save as New file is daunting!)
c.)I also would like to be able to display numbers in Number Format, but as 001, or 01, or 00009 if that is the way I want to display it. For some reason, in Number format, it will display these values as 1,1 and 9 resp. How do I do that?
d.)Autocomplete! I know I know everyone seems to ask this same question but seriously is it possible? I have drop downs for Names and Products, and one has to keep manually scrolling down, is there a way to atleast be able to put in the first letter and have all records starting with the 1st letter displayed? Or is using the combobox with setting the property to autocomplete the only solution? But I wasn't completely able to do that either!
e.) Well I 've been able to achieve everything in bits and pieces (with my limited VBA knowledge) , but not been able to make all the functionalities work together at once!
Any help would be highly highly appreciated!
Thanks a million for giving it a read atleast ! ( I know I wrote a lot)
Warm Regards,
Sailee
How can I set up a funtion or setting so that each time I print a specific worksheet in excel it automatically prints a seperate word document.
I have several worksheets of pricing quotes for different products and I would like to print the corresponding information about the product each time I print the individual worksheet.
Anyone have any pointers?
So the main user of a charting tool I made asked me about printing. Is there a way that I can run code before print? I would like to reorganize the sheet for printing so that only pertinent information is added to the print que.
Hello,
I need some help with printing charts. I have a workbook with several worksheets. Some (but not all) worksheets contain charts alongside the data. I would like to be able to print just the charts, two per page, the same size, hopefully just by clicking a button. Several people open the workbook and the charts on the sheets are moved and resized.
Is there anybody out there that can help?
Thanks,
Mark
I have this code which is kind of what I want. I am using it as a good explaination as to what I want to do as well as a starting point. I got it from "The Spreadsheet Page" It checks all the sheets in a workbook loads a dialog box and lists all the sheets with data in with a check box with an option to print them.
What I want is something very similar but checks for graphs. Obviously if there is a graph I would like it listed, so there is no need to check for data I think. I only have my graphs on a sheet named very originally "Graphs". So I don't think the code would need to check each sheet as this is doing.
Code:
Sub SelectSheets()
Dim i As Integer
Dim TopPos As Integer
Dim SheetCount As Integer
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim cb As CheckBox
Application.ScreenUpdating = False
' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If
' Add a temporary dialog sheet
Set CurrentSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add
SheetCount = 0
' Add the checkboxes
TopPos = 40
For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)
' Skip empty sheets and hidden sheets
If Application.CountA(CurrentSheet.Cells) 0 And _
CurrentSheet.Visible Then
SheetCount = SheetCount + 1
PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
PrintDlg.CheckBoxes(SheetCount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i
' Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240
' Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = Application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = 230
.Caption = "Select sheets to print"
End With
' Change tab order of OK and Cancel buttons
' so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront
' Display the dialog box
CurrentSheet.Activate
Application.ScreenUpdating = True
If SheetCount 0 Then
If PrintDlg.Show Then
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then
Worksheets(cb.Caption).Activate
ActiveSheet.PrintOut
' ActiveSheet.PrintPreview 'for debugging
End If
Next cb
End If
Else
MsgBox "All worksheets are empty."
End If
I have tried to adjust the various lines to relate to charts instead of sheets but was getting in a right kerfuffle. Whats more I have only just mastered the art of refering to sheets nevermind charts. I never dealt with dialog boxes.
This does seem a pretty big ask I know you like us to at least have try, but I know I will spead days on this without any help.
Thanks a lot, this will save my sanity if nothing else.
Partjob
If one a particular sheet the page setup shows you are spanning 2 printable pages of A4, 1 sheet with the charts on and the other with the data, can you tell excel to print the charts only but still keep the data visible? This would need to apply to a whole workbook where this situation applies on many sheets.
Had a quick search but to no avail and my brain's not up to speed yet - maybe not enough caffeine yet! Anyhoo - any ideas?
I have a project that requires the user to print 5 charts from excel. I want to automate the process as follows:
The user downloads the excel file to their hard drive
The user opens the file
A message box appears on sheet 1 and says "click yes to print the 5 charts or cancel"
If the user cancels, the message box is erased and only sheet 1 is visisble
If the user clicks on "yes" then the 5 charts are printed and the message box is erased and only sheet 1 is visible
Hello,
I have a worksheet where I made a bunch of charts. Is there some way that I can print only the charts on a sheet, each on an individual page?
I don't want to select each one and press print, there are a lot.
Thanks,
-dif-
I have a macro that takes 1 worksheet of data and makes multiple sheets and embeds a chart on each sheet. The Macro works great. I need to make another for printing the charts, and still trying to learn loops.
Below is the chart name. I use this macro for multiple files so somethime only 10 sheets with charts on them and sometimes 40. There will be a chart on every sheet except for the sheets named "Index" and "Input".
ActiveSheet.ChartObjects("Chart 1").Activate
Thanks for your help
|
|