+ Reply to Thread
Results 1 to 3 of 3

[SOLVED] Trouble with module wide variable

Hybrid View

saabman [SOLVED] Trouble with module... 03-10-2009, 05:16 AM
dominicb Re: Trouble with module wide... 03-10-2009, 05:26 AM
saabman Re: Trouble with module wide... 03-10-2009, 05:41 AM
  1. #1
    Registered User
    Join Date
    03-28-2007
    Posts
    6

    Question [SOLVED] Trouble with module wide variable

    Hi

    I am trying to get a module wide variable to provide the current filename to the various subs...

    Private CurrentFileName As String
    '-----------------------------------------------------------------------------------------
    Sub GetCurrentFileName()
    
    CurrentFileName = Cells("sFileName").Value
    MsgBox CurrentFileName
        
    End Sub 'GetCurrentFileName
    It seems I can't say the "CurrentFileName" be a cell value.
    why is this? I used the =CELL("fileneme") in the cell which I then gave a name to "sFileName". I get get the value if I declare the variable in the sub but not if it is declared at the beginning of the module...

    I am a bit of a beginner at this
    Thank you for any help you could provide
    Last edited by saabman; 03-10-2009 at 05:42 AM.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile Re: Trouble with module wide variable

    Good morning saabman
    Quote Originally Posted by saabman View Post
    I am trying to get a module wide variable to provide the current filename to the various subs...

    It seems I can't say the "CurrentFileName" be a cell value.
    why is this? I used the =CELL("fileneme") in the cell which I then gave a name to "sFileName". I get get the value if I declare the variable in the sub but not if it is declared at the beginning of the module...
    You don't have to get the file name from a cell - you can just pick it straight up from VBA. Whether you use the .Name command or .FullName command depends on whether you want to see just the filename or the full path :
    MsgBox ThisWorkbook.Name
    MsgBox ThisWorkbook.FullName
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    03-28-2007
    Posts
    6

    Re: Trouble with module wide variable

    wow thanx for that LOL I should have guessed LOL

+ 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