+ Reply to Thread
Results 1 to 3 of 3

How can I print all the charts in a workbook?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-21-2007
    Posts
    118

    How can I print all the charts in a workbook?

    I have a workbook that has 10 data worksheet and from these I create another 10 charts (not embedded, just chart sheetS).

    How can I print the charts only with a macro? I have found many examples to print charts embedded in worksheets but none that just prints any chart found in the workbook.

    Any ideas?

    The macro I've been trying is the following (trying to print a worksheet by matching a string to its name - since "chart" is always included in my chart sheets name)
    Sub PrntAll()
    Dim match as string
    match = "chart"
    dim sheet as worksheet
    
    for each sheet in thisworkbook.worksheets
    
    if Instr(1,UCase(sheet.name),ucase(match),1,) > 0 then
    sheet.printout copies:=1
    end if
    next
    
    end sub
    I tried playing around with capitals and small letters but it won't work.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482
    Rather than looping through the worksheets, which will never include your chart sheets, use the charts object instead.

    And if you want all the chart sheets you do not need to do the IF test.
    Sub PrntAll()
    Dim match as string
    match = "chart"
    dim sheet as chart
    
    for each sheet in thisworkbook.charts
    
    if Instr(1,UCase(sheet.name),ucase(match),1,) > 0 then
    sheet.printout copies:=1
    end if
    next
    
    end sub
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    03-21-2007
    Posts
    118
    Excellent!!

    Thank you very much!!

    It works perfectly (just needs a correction to remove a comma at the end of the Instr parentheses after number 1).

    Thank you again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1