Solved

Two Copies of chart printing on the Same Sheet

Posted on 2012-03-27
7
481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 42

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 42

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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 42

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 42

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

732 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