Solved

VBA - Editing Header on "Chart" Worksheet

Posted on 2010-09-01
4
916 Views
Last Modified: 2012-06-27
Experts,

I have a sub that clears the center header box and then puts in text along with some date variables. This is working fine, on the worksheets (SumOfActivity and SalesActivityQuery) within my workbook, however I have a “Chart Sheet”, thus calling it such as:

Set WS = ChartOfActivities
      WS.PageSetup.CenterHeader = “”
      WS.PageSetup.CenterHeader = “&B&14&””MONTHLY SUMMARY”… etc.

Results in Error 13 – Type Mismatch

How can I call the “Chart Sheet”? Do I need to DIM this differently then:

Dim WS As Worksheet

I tired Dim CH As Chart, or the Chart name itself.

Code and screen shot below.

Thank you in advance,
Kevin

Private Sub UpdateHeaderDataVariable()

    Application.ScreenUpdating = False
    Dim WS As Worksheet, sTmp As String
    
    Set WS = SumOfActivity
        WS.PageSetup.CenterHeader = ""
        WS.PageSetup.CenterHeader = "&B&14&""Arial""MONTHLY ACTIVITY" & vbCr & "Count of ALL" & vbCr & "From " & Format(dtIN1, "MM/DD/YYYY") & " to " & Format(dtIn2, "MM/DD/YYYY")
             
   Set WS = ChartOfActivities
       WS.PageSetup.CenterHeader = ""
       WS.PageSetup.CenterHeader = "&B&14&""Arial""New Business - " & Format(dtIN1, "MMMM YYYY")
    
    Set WS = SalesActivityQuery
        WS.PageSetup.CenterHeader = ""
        WS.PageSetup.CenterHeader = "&B&14&""Arial""Monthly Chart" & vbCr & "From " & Format(dtIN1, "MM/DD/YYYY") & " to " & Format(dtIn2, "MM/DD/YYYY")

End Sub

Open in new window

EE-Chart-Header-VBA-ERROR.jpg
0
Comment
Question by:redrumkev
[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
  • 2
4 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 33581670
Does this work?

Dim ws as Object
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 33581676
You can't declare WS as worksheet, because that will only allow Worksheets. If you wish to re-use the WS variable, you will need to declare it as "Object", or declare another variable for your chart sheets.

FWIW, this works fine for me...

    Dim ch As Chart
    Set ch = Sheets("Chart1")
    With ch.PageSetup
        .CenterHeader = "HEADER"
    End With

Also, if you are using the code name, do you need to declare a variable for it at all?

Wayne
0
 
LVL 23

Author Comment

by:redrumkev
ID: 33582512
Wayne,

The following worked perfectly, THANK YOU!

Kevin

Private Sub UpdateHeaderDataVariable()

    Application.ScreenUpdating = False
    Dim WS As Worksheet, CH As Object, sTmp As String
    
    Set WS = SumOfActivity
        WS.PageSetup.CenterHeader = ""
        WS.PageSetup.CenterHeader = "&B&14&""Arial""FIRST HEADER"
             
    Set CH = ChartOfActivities
        CH.PageSetup.CenterHeader = ""
        CH.PageSetup.CenterHeader = "&B&14&""Arial""CHART HEADER"
    
    Set WS = SalesActivityQuery
        WS.PageSetup.CenterHeader = ""
        WS.PageSetup.CenterHeader = "&B&14&""Arial""HEADER SALES"

End Sub

Open in new window

0
 
LVL 23

Author Closing Comment

by:redrumkev
ID: 33582517
Thank you!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
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 …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

635 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