1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: VBA Excel calling functions

Discussion in 'Business Applications' started by NZGiraffe, Aug 7, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. NZGiraffe

    NZGiraffe Thread Starter

    Joined:
    Aug 7, 2011
    Messages:
    3
    Hi there,

    I have a problem with calling some functions in vba excel.

    I have a workbook with a single worksheet. In VBA I have all my code in the Sheet1 object including this:

    Code:
    Sub OpenSetup()
        Call CheckDate
        If DateInRange = 1 Then
            Call DeHighlightYesterday
            Call HighlightToday
            
        Else
            MSGOPEN = MsgBox("A new week has started. Do you want to update the calender?", vbYesNo)
                If MSGOPEN = vbYes Then
                    Call XFRCLEAR
                Else
                    MsgBox "OK, please click ""Update Calender"" when your ready."
                End If
        End If
        Range("D8").Activate
        MsgBox "Welcome, enjoy your stay"
    End Sub
    
    Then under the ThisWorkbook object I have...

    Code:
    Sub Workbook_Open()
        Call OpenSetup
    End Sub
    
    ...intending to run the OpenSetup function when the workbook is opened. However when I step through to make sure it works I get this error message:

    "Compile Error: Sub or Function not defined"

    I am sure I am missing something very simple but I am just beginning with VBA and have drawn a blank.
     
  2. NZGiraffe

    NZGiraffe Thread Starter

    Joined:
    Aug 7, 2011
    Messages:
    3
    hmm, should I have all my code under a module rather than the worksheet object?
     
  3. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,550
    First Name:
    Hans
    Hi, welcome to the forum.
    Yes, it's advisable to have these in a separate module instead of a sheet.
    The sheet's vba are okay but when to call another function or macro will not recognize these if they are in a sheet's vba and not in the general vba project module.
     
  4. NZGiraffe

    NZGiraffe Thread Starter

    Joined:
    Aug 7, 2011
    Messages:
    3
    Thanks Keebellah,

    Yeah - got it figured myself - rookie mistake. Cheers for the help
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1011289

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice