+ Reply to Thread
Results 1 to 4 of 4

Public variables

  1. #1
    Registered User
    Join Date
    08-31-2005
    Posts
    48

    Public variables

    Hi,

    My public variables can't be referenced by sub routines in my modules. The two msgboxes in the code below display them correctly.


    Public newDataSheet As Worksheet
    Public nikkeiTime As Date

    Private Sub Workbook_Open()

    Set newDataSheet = Workbooks("Historic Data").Worksheets("NewData")
    nikkeiTime = "00:00:05"

    MsgBox nikkeiTime
    MsgBox newDataSheet.name

    Application.OnTime Now + TimeValue("00:00:01"), "runSchedule"

    End Sub


    However the msgboxes in runSchdule are blank, code shown below

    Sub runSchedule()

    MsgBox nikkeiTime
    MsgBox newDataSheet.name

    End Sub

    Can anybody help me with this one please?

    Thanks

    T

  2. #2
    Tom Ogilvy
    Guest

    RE: Public variables

    Put the public variables in a general module, not the thisworkbook module.
    You can still initialize them in the Workbook_Open event. Your runSchedule
    routine should also be in a general module.

    --
    Regards,
    Tom Ogilvy


    "Tomski" wrote:

    >
    > Hi,
    >
    > My public variables can't be referenced by sub routines in my modules.
    > The two msgboxes in the code below display them correctly.
    >
    >
    > Public newDataSheet As Worksheet
    > Public nikkeiTime As Date
    >
    > Private Sub Workbook_Open()
    >
    > Set newDataSheet = Workbooks("Historic Data").Worksheets("NewData")
    > nikkeiTime = "00:00:05"
    >
    > MsgBox nikkeiTime
    > MsgBox newDataSheet.name
    >
    > Application.OnTime Now + TimeValue("00:00:01"), "runSchedule"
    >
    > End Sub
    >
    >
    > However the msgboxes in runSchdule are blank, code shown below
    >
    > Sub runSchedule()
    >
    > MsgBox nikkeiTime
    > MsgBox newDataSheet.name
    >
    > End Sub
    >
    > Can anybody help me with this one please?
    >
    > Thanks
    >
    > T
    >
    >
    > --
    > Tomski
    > ------------------------------------------------------------------------
    > Tomski's Profile: http://www.excelforum.com/member.php...o&userid=26824
    > View this thread: http://www.excelforum.com/showthread...hreadid=570344
    >
    >


  3. #3
    Registered User
    Join Date
    08-31-2005
    Posts
    48
    Thanks mate, just the job.

    T

  4. #4
    Snake Plissken
    Guest

    Re: Public variables

    > Set newDataSheet = Workbooks("Historic Data").Worksheets("NewData")


    does it really work ??

    dont think so

    why dont you use "option explicit" directive ?



+ 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