Solved

Two Copies of chart printing on the Same Sheet

Posted on 2012-03-27
7
475 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

864 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