Results 1 to 2 of 2

Thread: [VBA] RE GetOpenFileName, I want to point Excel to a file, and then reference that in other modules
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Aug 2018
    Posts
    248
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default [VBA] RE GetOpenFileName, I want to point Excel to a file, and then reference that in other modules

    Hi all,

    Doing a new sheet for reporting, I want to report on a campaign. Let's say our campaign is called "70. London"

    I use GetOpenFilename to point Excel to this, and then reference that file as 'facml'

    So now when I talk about facml in that module, it knows the file name and location, so if I need to open it, I can just write "facml.open" false (for read only)

    That's all well and good in that module, but what about in other modules?

    Let's say I have another module that needs to open facml and grab some information from it, will I have to do the "get open filename" process again, or can I just point it to my existing facml that I already defined in the other module?

    A potential workaround I'm seeing is to write the path and filename string for facml in a cell that's out of sight, and then say facml = cell, to then open that filename.

    Thanks.

  2. #2
    Board Regular
    Join Date
    Jun 2011
    Posts
    1,399
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: [VBA] RE GetOpenFileName, I want to point Excel to a file, and then reference that in other modules

    You can declare facml outside any function and sub and with the PUBLIC keyword. That makes facml a global variable, which can be used by all modules and, thus, could be hard to track in a big project.
    Code:
    Public facml As Workbook
    An alternative is to pass it by reference.
    Excel 2010, Windows 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •