+ Reply to Thread
Results 1 to 4 of 4

Open a file with varying filename

  1. #1
    Registered User
    Join Date
    12-29-2011
    Location
    San Diego, Ca.
    MS-Off Ver
    Excel 2007
    Posts
    60

    Open a file with varying filename

    I'd like to open a file from within VBA whose name will change based on user input (Inputbox). The following VBA code opens a specific file
    (filename1):

    #Set WBInput = Workbooks.Open("C:\users\myname\documents\folder\filename1")#

    But how can the name "filename1" be written to be a variable name? Seems like concatenation of some kind should work but after multiple attempts I can't figure it out.

    Thanks in advance.

  2. #2
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Open a file with varying filename

    try this
    Please Login or Register  to view this content.
    Thanks - Naveed
    -----------------------------
    If the suggestion helps you, then Click * to Add Reputation
    To Attach File: Go Advanced>>Manage Attachments>>Add Files (In Top Right Corner)>>SelectFiles>>.........Locate Your File(s)>>Upload Files>>Done (In Bottom Right)
    1. Use [code] code tags [\code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Open a file with varying filename

    Hi gotocm,

    Instead of trying to predict what file is to be opened in the VBA I do this command.
    Please Login or Register  to view this content.
    Which brings up a dialog box and the user can click on the file they want.

    See if it can work for you...
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    12-29-2011
    Location
    San Diego, Ca.
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Open a file with varying filename

    Thanks Marvin. This definitely works but I was trying to avoid having to search through a list of files for the correct file. I wanted to have that done automatically. But you have taught me yet another new trick. VBA has a seemingly endless number of objects and at times extremely frustrating to figure them out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 10-23-2013, 12:54 AM
  2. Replies: 1
    Last Post: 09-09-2013, 11:41 AM
  3. [SOLVED] use a macro to Open a file with a variable filename
    By plunkettyplunk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-05-2013, 03:03 PM
  4. Macro: Open file but the filename changes
    By FLani in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2013, 06:36 AM
  5. Search for Filename with Date and Open File
    By Gingeiko in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-29-2011, 08:11 PM

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