+ Reply to Thread
Results 1 to 7 of 7

If err.number... gives expected function or variable in Excel 2016

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: If err.number... gives expected function or variable in Excel 2016

    Ah, yes... That's called 'OverLoading'

    An example. Say all your MsgBoxes have the same Icon, Buttons and Caption. Only thing that changes is the message. Write a Public Function 'MsgBox' that takes only the message as a parameter
    
    Sub Test()
    
       If MsgBox("What to do") = vbYes Then
           ' Do something
       End If
    End Sub
    
    Public Function MsgBox(strMessage as String) as vbMsgBoxResult
    
        MsgBox = VBA.MsgBox(strMessage, vbQuestion + VBYesNo + vbDefaultButton2, "Standard Caption")
    
    End Function
    Your 'MsgBox' will run when called from Sub Test (or any procedure that does not qualify the call to MsgBox) as that will be the first MsgBox function found by the compiler, but that then calls the VBA MsgBox because it explicitly references the Library containing it - 'VBA.MsgBox'. Much the same as calling a procedure in another module in your code.
    Last edited by grimes0332; 02-26-2016 at 11:23 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Getting compile error expected function or variable
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-10-2014, 01:33 AM
  2. [SOLVED] Shell Function "Compile Error: Expected procedure, not variable"
    By s0713190@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-09-2014, 01:20 PM
  3. [SOLVED] Compile Error Expected Function or Variable
    By shiser in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-22-2014, 09:18 AM
  4. [SOLVED] Compile error expected function or variable (on protect method)
    By Tirren in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-30-2013, 03:22 PM
  5. Expected function or variable error
    By Arimpact in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-09-2011, 07:48 PM
  6. Compile Error:- expected function or variable problem
    By skin.uk1 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-08-2011, 02:56 PM
  7. Expected Function or Variable Error !!
    By BouncingHippo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-02-2008, 07:47 PM

Tags for this Thread

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