Two Copies of chart printing on the Same Sheet

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
BROOKLYN1950Asked:
Who is Participating?
 
dlmilleConnect With a Mentor Commented:
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
 
dlmilleCommented:
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
 
dlmilleCommented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
BROOKLYN1950Author Commented:
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
 
BROOKLYN1950Author Commented:
Actually what you missed is that the code is being called from the user form.  I print fine from the Excel sheet.
0
 
dlmilleCommented:
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
 
BROOKLYN1950Author Commented:
nice job on locating the bug.  i alraeady re did this project, doing all the printing from the workbook
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.