[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Two Copies of chart printing on the Same Sheet

Posted on 2012-03-27
7
Medium Priority
?
488 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

656 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