+ Reply to Thread
Results 1 to 9 of 9

Changing data in footer in VBA

  1. #1
    Registered User
    Join Date
    12-19-2004
    Location
    Adelaide
    Posts
    8

    Red face Changing data in footer in VBA

    Hi experts,

    Is there a way to manipulate the footer in such a way that each successive page printed has a different alpha-numeric number in the footer. This number would be related to the data on each page e.g. it could be cell A20 for page1 , cell A40 for page 2, etc.

    Thanks

    Hans

  2. #2
    William Benson
    Guest

    Re: Changing data in footer in VBA

    Something like this?


    Sub PrintMe()
    Dim Cel As Range
    Dim i As Long
    Dim Sh As Worksheet
    Dim Rng As Range
    Dim Pages As Long

    Pages = Int(Range(ActiveSheet.PageSetup.PrintArea).Rows.Count / 20)

    For i = 1 To Pages
    With ActiveSheet.PageSetup
    .LeftFooter = Range("A" & 20 * i)
    'simlar code for other footers
    End With
    ActiveWindow.SelectedSheets.PrintOut From:=i, To:=i, _
    Copies:=1, Collate:=True
    Next i
    End Sub



    "Hans47" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi experts,
    >
    > Is there a way to manipulate the footer in such a way that each
    > successive page printed has a different alpha-numeric number in the
    > footer. This number would be related to the data on each page e.g. it
    > could be cell A20 for page1 , cell A40 for page 2, etc.
    >
    > Thanks
    >
    > Hans
    >
    >
    > --
    > Hans47
    > ------------------------------------------------------------------------
    > Hans47's Profile:
    > http://www.excelforum.com/member.php...o&userid=17600
    > View this thread: http://www.excelforum.com/showthread...hreadid=384412
    >




  3. #3
    Registered User
    Join Date
    12-19-2004
    Location
    Adelaide
    Posts
    8
    Thanks William,

    Tried this with a button on Excel but came up with a VBA warning '400' - no explanation. If I run the macro from VBA it tells me

    method 'Range' of Object '_Global' failed

    When I run it again it now says

    application defined or object-defined error

    What the...

    I'm using Excel 2000-SP3.
    Thanks again.

  4. #4
    Registered User
    Join Date
    12-19-2004
    Location
    Adelaide
    Posts
    8

    Data in Footer

    Hi again William,

    Just another thing I tried..

    the problem appears to be in the line calculating 'Pages' - it results in a zero
    which then causes the error.

    Hans

  5. #5
    William Benson
    Guest

    Re: Changing data in footer in VBA

    You have not assigned the PrintArea?

    Just a guess ...

    "Hans47" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi again William,
    >
    > Just another thing I tried..
    >
    > the problem appears to be in the line calculating 'Pages' - it results
    > in a zero
    > which then causes the error.
    >
    > Hans
    >
    >
    > --
    > Hans47
    > ------------------------------------------------------------------------
    > Hans47's Profile:
    > http://www.excelforum.com/member.php...o&userid=17600
    > View this thread: http://www.excelforum.com/showthread...hreadid=384412
    >




  6. #6
    Registered User
    Join Date
    12-19-2004
    Location
    Adelaide
    Posts
    8

    Smile Changing data in footer

    Hi William,

    Thanks! that works.

    Hans

  7. #7
    JMB
    Guest

    Re: Changing data in footer in VBA

    It looks like you are trying to determine the number of printed pages. This
    may help.

    pgcnt = ExecuteExcel4Macro("Get.Document(50)")

    This is from:

    http://j-walk.com/ss/excel/tips/tip65.htm

    "William Benson" wrote:

    > You have not assigned the PrintArea?
    >
    > Just a guess ...
    >
    > "Hans47" <[email protected]> wrote in
    > message news:[email protected]...
    > >
    > > Hi again William,
    > >
    > > Just another thing I tried..
    > >
    > > the problem appears to be in the line calculating 'Pages' - it results
    > > in a zero
    > > which then causes the error.
    > >
    > > Hans
    > >
    > >
    > > --
    > > Hans47
    > > ------------------------------------------------------------------------
    > > Hans47's Profile:
    > > http://www.excelforum.com/member.php...o&userid=17600
    > > View this thread: http://www.excelforum.com/showthread...hreadid=384412
    > >

    >
    >
    >


  8. #8
    Registered User
    Join Date
    12-19-2004
    Location
    Adelaide
    Posts
    8

    Data in Footer

    Thanks JMB, that works well.

    Another question: is it possible to do this using the Workbook_BeforePrint

    command - so that I don't have to create a new print window to

    print a selection of pages (or only one page) and also maintain the Excel print

    preview.

  9. #9
    William Benson
    Guest

    Re: Changing data in footer in VBA

    Thanks - exactly what was missing in my bag of tricks, thanks for helping
    both the OP and ME TOO JMB!!

    "JMB" <[email protected]> wrote in message
    news:[email protected]...
    > It looks like you are trying to determine the number of printed pages.
    > This
    > may help.
    >
    > pgcnt = ExecuteExcel4Macro("Get.Document(50)")
    >
    > This is from:
    >
    > http://j-walk.com/ss/excel/tips/tip65.htm
    >
    > "William Benson" wrote:
    >
    >> You have not assigned the PrintArea?
    >>
    >> Just a guess ...
    >>
    >> "Hans47" <[email protected]> wrote in
    >> message news:[email protected]...
    >> >
    >> > Hi again William,
    >> >
    >> > Just another thing I tried..
    >> >
    >> > the problem appears to be in the line calculating 'Pages' - it results
    >> > in a zero
    >> > which then causes the error.
    >> >
    >> > Hans
    >> >
    >> >
    >> > --
    >> > Hans47
    >> > ------------------------------------------------------------------------
    >> > Hans47's Profile:
    >> > http://www.excelforum.com/member.php...o&userid=17600
    >> > View this thread:
    >> > http://www.excelforum.com/showthread...hreadid=384412
    >> >

    >>
    >>
    >>




+ 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