+ Reply to Thread
Results 1 to 3 of 3

Function and Personal.xls

  1. #1
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562

    Exclamation Function and Personal.xls

    Somewhere I read that if you want a sub or function to be available to all of your programs, you should put it in Personal.xls. Okay, I put the following in my Personal.xls file under Modules.

    Public Function WorkbookIsOpen(wbname) As Boolean

    ' Returns TRUE if the workbook is open

    Dim x As Workbook
    On Error Resume Next
    Set x = Workbooks(wbname)
    If Err = 0 Then
    WorkbookIsOpen = True
    Else
    WorkbookIsOpen = False
    End If

    End Function


    In another file I attempt to use the function, but I get Compile Error: Sub or Function not defined.

    wbopen = WorkbookIsOpen("File Name.xls")
    If wbopen <> True Then
    Workbooks.Open Filename:="C:\File Cabinet\Recon\File Name.xls"
    End If


    Can any tell me what I am doing wrong or what else I need to do to get this to work or a better method altogether. I use this function a lot and up to this point I have simply put it in file due to lack of time to research a better way. Now that I have discovered this list I have finally finded the resource I need to improve my programming skills.

    Thanks!

  2. #2
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    Found the answer.

    In VBE you go to Tools > References and check the box next to "Personal".

    If you do not see "Personal", go back out and look at at your Project Explorer. If is says something like VBAProject (Personal.xls) then you need to right click on the project, go into properties and then give it a Project Name of "Personal". It will then be easily identifiable in the References list.

    The function worked great after that.

    Thank you Richard from MrExcel for getting me pointed in the right direction.

    Jeff

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,849
    I could be wrong, but I think that in order to call a VBA function from a VBA routine in another project, the calling project needs to include a reference to the project containing the function. So, in this case, the files that want to call this function need to contain a reference to Personal.xls.

+ 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