+ Reply to Thread
Results 1 to 3 of 3

Pass Filenames into Macro

  1. #1
    Registered User
    Join Date
    06-29-2012
    Location
    u
    MS-Off Ver
    Excel 2007
    Posts
    2

    Pass Filenames into Macro

    I'm trying to run a macro that will open up a user-selected filename. I can successfully pass a filename into a function, as I show below, but apparently functions can't run Excel commands such as a workbook open. It passes the filename, but does not open it.

    Function OpentheFile(TheFileName as String)
    Workbooks.Open FileName:=TheFileName
    End Function

    So I tried using a Sub. If I directly input the filename like below, then the file opens.

    Sub OpentheFile()
    Workbooks.Open FileName:="C:\Documents\file.xls
    End Sub

    But I can't add parameters to pass into the Sub. It returns some indication of an invalid command when I do this.

    So essentially what I want is to pass a Macro a filename, and the Macro to open it. Seems simple enough, but I can't figure it out. Thoughts?

  2. #2
    Forum Contributor
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    386

    Re: Pass Filenames into Macro

    How is the file path determined? Do you want to select it from a browser box? Or is it the same path as the workbook?

    i think what you need is a string variable.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-29-2012
    Location
    u
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Pass Filenames into Macro

    The file path is being passed from LabView as a string.

    EDIT: So in LabView, the user selects, from a file dialog, the filepath, and that filepath is converted into a string containing, for example, "C:\Documents\trace.xls". This string is then passed to the Macro call function in LabView, basically sending VBA the command (if it worked) FileOpen("C:\Documents\trace.xls"). But I can't get this last portion to work.
    Last edited by CodyKL; 06-29-2012 at 11:47 AM.

+ 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