Solved

Two Copies of chart printing on the Same Sheet

Posted on 2012-03-27
7
473 Views
Last Modified: 2012-04-01
I have a User Interface developed allowing the user to select which chart to print.  for Example if chart 1 is check, print it.  the proper chart is printed based upon the check marks but it prints out a full page chart plus a second copy of the chart, smaller super imposed on the first chart.

I first tried the prinout method but got the above results.  when I did a record macro of printing a single chart it gave me this code:

ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"

by adding a select chart it creates a nice sub

Sub PrintChart15()
    Chart15.Select
    ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
End Sub

this prints a full page chart.  I can run this sub separately and it gives me properly printed charts.

However, when I call these two subs based upon the following code, I get the same error with super imposed charts.

If ChBxCumGI = True Then
PrintChart15
End If
If ChbxGIOU = True Then
PrintChart22
End If

This makes no sense.  Help
0
Comment
Question by:BROOKLYN1950
  • 4
  • 3
7 Comments
 
LVL 41

Expert Comment

by:dlmille
ID: 37774668
Are these charts embedded, or on their own separate chart sheets?

I'm a bit confused to.  Your syntax would have me believe you are printing from chart sheets, re: Chart15.Select, however your comments lead me to believe that they are embedded charts.

Take a look at the example I attached, with two charts having names "Chart 15" and "Chart 22" as embedded charts.

The code I used, similar to yours, but working with embedded charts is:

Option Explicit

Sub PrintChart15()
    ActiveSheet.ChartObjects("Chart 15").Activate
    ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
End Sub

Sub PrintChart22()
    ActiveSheet.ChartObjects("Chart 22").Activate
    ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
End Sub

Sub printBothCharts()

    Call PrintChart15
    Call PrintChart22
    
End Sub

Open in new window


See attached and advise.

Dave
printCharts-r1.xls
0
 
LVL 41

Expert Comment

by:dlmille
ID: 37774681
If you are printing chart sheets, with the sheet names, respectively "Chart15" and "Chart22" then the code would be:

Option Explicit

Sub PrintChart15()
    Sheets("Chart15").Activate
    ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
End Sub

Sub PrintChart22()
    Sheets("Chart22").Activate
    ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
End Sub

Sub printBothCharts()

    Call PrintChart15
    Call PrintChart22
    
End Sub

Open in new window


see attached.

So, advise if you are working with embedded charts, or chart sheets.  The demonstration workbooks I've uploaded simulate both.  Let me know if the code enhancements have helped, etc.

In either scenario, when you print does the print work correctly, or do you get the image overlay?

Dave
printCharts-r2.xls
0
 

Author Comment

by:BROOKLYN1950
ID: 37785458
Sorry it took me so long to respond, but I won't have a chance to try your solution until Saturday.  I am working with chart sheets.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:BROOKLYN1950
ID: 37785461
Actually what you missed is that the code is being called from the user form.  I print fine from the Excel sheet.
0
 
LVL 41

Expert Comment

by:dlmille
ID: 37785462
How about posting your example?  You said User Interface which could be just about anything including User Form.  Lots of guessing on my part, eh?

Also, you didn't answer any of my questions.

I await your response.

Dave
0
 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
ID: 37785500
Success!  I was able to replicate your stated example by creating the combinations - it took a while.  You must be using chart sheets, not embedded charts, as they don't have a problem printing from Userform, however charts sheets do.

This is a bug with model Userform.  We can get around that bug by going modeless, then printing, then reverting back to modal.

E.g.,  on the print command, hide your userform, show it again as vbModeless, do the printing, then hide and convert back to vbModal.  The user might see a flicker, but not much.

here's the code:
Private Sub CommandButton1_Click()
    UserForm1.Hide
    UserForm1.Show vbModeless
    Call printBothCharts
    UserForm1.Hide
    UserForm1.Show vbModal
End Sub

Open in new window


See attached demonstration workbook.

sorry about the confusion on my end.

Cheers,

Dave
printCharts-Userform-r2.xls
0
 

Author Closing Comment

by:BROOKLYN1950
ID: 37793822
nice job on locating the bug.  i alraeady re did this project, doing all the printing from the workbook
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now