+ Reply to Thread
Results 1 to 7 of 7

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

  1. #1
    Forum Contributor
    Join Date
    09-17-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    117

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

    I'm trying to handle some errors using err.Number such as in:
    Please Login or Register  to view this content.
    This works in excel 2010 but in 2016, I get a compile error with "expected function or variable", so the code won't execute at all.

    I hope it's just something that needs enabling in 2016 somewhere, otherwise when we move onto 2016 as a company, a large amount of automation will fail.

    Is anyone using 2016 and able to use this function?

  2. #2
    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

    There's nothing wrong with that code - 2016 will not have changed that much (and hasn't, tested)

    Go to the Tools/References dialog. See if anything is marked as 'MISSING'

  3. #3
    Forum Contributor
    Join Date
    09-17-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    117

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

    I've compared the references between 2010 (works) & 2016 (fails) and the same five are all checked. None are marked as missing.

    The only difference is that instead of 'Microsoft Excel 14.0 Object library' (2010) it is 'Microsoft Excel 16.0 Object library' in 2016 (and the same for the office object library). 14.0 is not in the list to select.

    This is worrying as although we won't be likely to upgrade until support for Win7 expires (so a few years of life yet) when that day comes, most of the report automation and resource planning tools will just stop working. Not good when there's over 80k employees in the company.

    How can I handle specific errors now if I can't use an error handler?

    I have seen references to early/late binding to overcome this but can't say I'm clear on what I have to do or if it suits these circumstances.

  4. #4
    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

    The (changed) references are correct. 2010 is 14 object library, 2016 is the 16 object library.

    The code works - that syntax hasn't changed since the introduction of VBA so the issue is something else in your code/worksheet/environment. Just to make sure:
    Please Login or Register  to view this content.
    Pops a MsgBox saying '13 Type Mismatch'


    Early or Late binding has nothing to do with this. You are not binding to anything in this case.

  5. #5
    Forum Contributor
    Join Date
    09-17-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    117

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

    Well would you Adam and Eve it!

    Three hours of frustration at the compile error and it turns out to be 'environmental'!

    I ran your code in the current workbook - same issue.
    I ran it in a new workbook, worked fine.
    I then reopened the original workbook and then the code worked without the compile error.

    In a boolean environment, how can true or false become neither?

    Thanks alot for this - I'd have been faffing about in the same workbook all afternoon without your help - it triggered me to reopen it and now all is well again in the universe of ones and zeros.

  6. #6
    Forum Contributor
    Join Date
    09-17-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    117

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

    Update and resolution:

    I had stupidly named on of my test modules as sub err() and this was where the problem lay.

    I renamed it and all worked fine in the latest version of the workbook.

    Epic coding fail - schoolboy error of the highest order!

  7. #7
    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
    Please Login or Register  to view this content.
    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