Solved

VBA - Editing Header on "Chart" Worksheet

Posted on 2010-09-01
4
879 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 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

12 Experts available now in Live!

Get 1:1 Help Now