+ Reply to Thread
Results 1 to 7 of 7

VBA - Open file with wildcard in path

  1. #1
    Registered User
    Join Date
    11-17-2005
    Posts
    4

    VBA - Open file with wildcard in path

    hello - what I want to do is have VBA code find a filename, open it, and then copy part of a spreadsheet into the existing open spreadsheet. The problem is, I want to use a wildcard in the Path name.

    Example: I want to open a file "g:\admin\1234_Client Name\2015PlanSpecs.xls"
    1234 is defined by a variable called "ClientNumber"
    Client Name is where I want to put the wildcard. The client can be identified by it's number, and I don't want the user to have to input the plan name as well. As long as a wildcard is only in the filename, it works, but I can't get it to work with a wildcard in the path. Can someone help?


    Please Login or Register  to view this content.
    Thanks.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA - Open file with wildcard in path

    Hello bshawn,

    Try this version and let me know the results.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-17-2005
    Posts
    4

    Re: VBA - Open file with wildcard in path

    I get an error on the "With" statement. I get "Compile Error: Sub or Function not defined"

    With CreateObject("Shell.application")
    Set ASCpath = .Namespace("G:\admin\")
    Endwith

    Thanks.

  4. #4
    Registered User
    Join Date
    11-17-2005
    Posts
    4

    Re: VBA - Open file with wildcard in path

    I get an error on the "With" statement. I get "Compile Error: Sub or Function not defined"

    With CreateObject("Shell.application")
    Set ASCpath = .Namespace("G:\admin\")
    Endwith

    Also, if you could explain what the 32 means in "Folders.filter 32" that would be great.
    Thanks.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA - Open file with wildcard in path

    Hello bshawn,

    I don't know why you are receiving that error. If you machine did not support the Shell object, you would have received a message like "Can not create ActiveX component".

    The syntax as written is also correct. Did you place this code inside a Sub or Function in your workbook?

    The 32 is a flag that indicates only folders are to be filtered. The flag is set to 64 when filtering only files.

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: VBA - Open file with wildcard in path

    Leith I am just guessing that he has taken the decimal point in front of Namespace???
    bshawn, do you still have the decimal point in front of Namespace in the with statement?
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA - Open file with wildcard in path

    Hello JapanDave,

    That's a good point. No pun intended. It is present in the code he posted with the error message.

+ 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. Can I use the asterisk (*) wildcard to save file in multiple PATH ???
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-30-2014, 01:29 PM
  2. Automatically open a file in a specific file path when another sheet is opened
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2014, 11:05 AM
  3. Replies: 5
    Last Post: 09-29-2012, 12:40 PM
  4. Issue Using DIR() to Find and Open File Using a Wildcard
    By goodasgone81 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-16-2012, 11:12 AM
  5. VBA Changing a fixed file path with open file dialog box
    By Dan27 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2011, 08:54 AM
  6. open file path
    By Bigelk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2011, 09:00 AM
  7. Open Word file form Excel using VBA and file path
    By psychoPETE in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-05-2010, 07:02 PM

Tags for this Thread

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