Consulting

Results 1 to 9 of 9

Thread: count shapes

  1. #1
    VBAX Regular
    Joined
    Jul 2008
    Posts
    8
    Location

    count shapes

    I am trying to figure out how to tell vba to count all the shapes in a document. Afterwards i would like it to select the last (furthest to the right) shape and depending on what page it is, print that many pages.

    If anyone could help me here, i would really appreciate it. I know it can't be to complicated but i just don't get it.

    Thanks so much
    Peter

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    ARe you talking about Excel or Word here?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jul 2008
    Posts
    8
    Location
    about Excel

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Well, the question made it sound like Word.

    To clarify, you wa nt to find the last sheet with a shape on it, and then print all sheets up to that?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Jul 2008
    Posts
    8
    Location
    yeah, i know. As soon as you wrote it i realized.
    Sorry about that.

    "you wa nt to find the last sheet with a shape on it, and then print all sheets up to that?"
    Yes exactly.

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Surely because of your statement you only need to check if a sheet has a shape then print the sheets that have one?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Maybe Simon, but I am reading it as all sheets upto last with a shape, regardless of whether they all have shapes?

    [vba]

    Dim sh As Worksheet
    Dim arySheets() As String
    Dim i As Long
    Dim LastSheet As Long

    With ActiveWorkbook

    ReDim arySheets(1 To .Worksheets.Count)
    For Each sh In .Worksheets

    i = i + 1
    arySheets(i) = sh.Name
    If sh.Shapes.Count > 0 Then

    LastSheet = i
    End If
    Next sh
    If LastSheet > 0 Then

    ReDim Preserve arySheets(1 To LastSheet)
    Worksheets(arySheets).PrintPreview
    End If
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Regular
    Joined
    Jul 2008
    Posts
    8
    Location
    yes, xld is right.
    it doesn't matter whether there are shapes on each single page (even though there will be)
    if the shape furthest right is on page five, for example, then i would like to print five pages

    there are two little problems still though.
    first, i would like to have it select sheet(2) and don't know where to write down sheets(2).select or activate
    second, the program ends in the printpreview, exactly what i want. But(since there is other information on the page as well, such as writing in some cells and backround color) it wants to print more pages than i like it to.
    On the bottom of my page it will say for example page 5/10 even though that is my last page. One way i could think of is telling excel to delete everything to the right of the last shape. But here again, not enough knowledge of VBA to even come up with a clue of how to do it.

    Thanks so much again. I really appreciate the help

    Peter

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Wouldn't it be better for you to tidy up the worksheets, as a manual process? It should only be aonce-off.

    What do you mean about selecting Sheet2? At what point?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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