+ Reply to Thread
Results 1 to 4 of 4

Compile Error - Type Mismatch

Hybrid View

  1. #1
    Registered User
    Join Date
    04-13-2012
    Location
    UK
    MS-Off Ver
    Excel 03 and 10
    Posts
    25

    Angry Compile Error - Type Mismatch

    Hi All,

    I have workbook which is prompting the user to save a copy as...acting like a sort of template I guess. I have a routine which runs when the workbook opens to test whether the workbook name matches the default name, if it does then the user is prompted to save a copy, if not, it does nothing. I had this working fine in a test workbook, but when I copied the module over to the actual workbook I got a compile error: Type mismatch. The code is fails on is..

    If MyName = "Forecast Template.xlsm" Then
    Where MyName is defined as

    Function MyName() As String
    MyName = ThisWorkbook.Name
    End Function
    The debug highlights the "=" sign when the code is run. Can anyone help me please?

    Note: I have also tried replacing the = sign with "Is".

    Thank you

  2. #2
    Registered User
    Join Date
    04-13-2012
    Location
    UK
    MS-Off Ver
    Excel 03 and 10
    Posts
    25

    Re: Compile Error - Type Mismatch

    I Just cannot understand why it would work in one workbook, but when copied and the filename changed, it no longer works! Madness!

  3. #3
    Registered User
    Join Date
    04-13-2012
    Location
    UK
    MS-Off Ver
    Excel 03 and 10
    Posts
    25

    Re: Compile Error - Type Mismatch

    Thank you to anyone looking at this, but I solved it by using
    If ThisWorkbook.Name= "Filename.xlsm" Then
    Must have been something to do with the Myname Routine?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Compile Error - Type Mismatch

    If that takes care of your original query, please select Thread Tools from the menu above and mark the thread as solved. Thanks.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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