Consulting

Results 1 to 7 of 7

Thread: Self define function shows error

  1. #1
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location

    Self define function shows error

    The code below works fine but shows #VALUE! when applied in worksheet
    Example, A1
    = pagerow(2) = #VALUE!
    Any suggestion?
    Emily


    Function pagerow(pagenumber As Integer) As Integer 
        pagerow = (Application.ExecuteExcel4Macro("INDEX(GET.DOCUMENT(64)," & _
    pagenumber & ")") - 1) 
    End Function 
     
    Sub test() 
        RowofPage = pagerow(2) 
    End Sub

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try one of these.


    Option Explicit
     
    Function PageRow(PageNumber As Long) As Long
    PageRow = ActiveSheet.HPageBreaks(PageNumber ).Location.Offset(-1, 0).Row
    End Function
    
    Function PageRow2(PageNumber As Long, Ancor As Range) As Long
    PageRow2 = Ancor.Parent.HPageBreaks(PageNumber ).Location.Offset(-1, 0).Row
    End Function

    Also, make sure the page exists (i.e., make sure that there is text in a cell on that page).

  3. #3
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    DRJ

    Thanks for your reply.

    Does Application.ExecuteExcel4Macro("INDEX(GET.DOCUMENT(64)," & pagenumber & ")") - 1) not appliable as a function?

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    I can't say with 100% certainty, but it would not work for me.

  5. #5
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    For those interest in this topic, please read the probably answer by Insomniac posted in JMT
    http://www.puremis.net/excel/cgi-bin...5856;start=0#4

  6. #6
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Yes, that's correct. You cannot use Excel4Macros in UDF's. I'm wondering why you can't just utilize the GET.DOCUMENT properties as the named range? This is the standard workaround. No need for a UDF.

    IrishDave mentions this at Colo's board (from your link). Paddy shows some working solutions here.

  7. #7
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    firefytr,

    Thanks for your reply

    Actually, I seldom use Excel4Macros in my own worksheet.

    The question is quoted from one Chinese Excel discussion board and just for my interest.

    Thanks for the sharing.
    Emily

Posting Permissions

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