+ Reply to Thread
Results 1 to 6 of 6

Create Query with variable for filename?

  1. #1
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Create Query with variable for filename?

    Hello...

    I am building a macro that runs the process to create a data table via query, but I'm not able to get the syntax correct when I use a variable for the file name.

    When I use the macro recorder, I get this beast at the top of the results
    Please Login or Register  to view this content.
    I am trying to get my variable, strFilename, to replace this mess:
    Please Login or Register  to view this content.
    I've tried messing with the quotation marks, but can't seem to get something like this to work, no matter what I try.
    Please Login or Register  to view this content.
    Anybody out there know how to do it?

    Also, I know it seems odd to use the table query for another .xlsx file, but the source file has Asian Characters, and any other way I try to import them leaves a bunch of garbled characters (ANSI, I think). When I do the query manually, the results look perfect. I've tried using the DATA/IMPORT features as well, but to no avail.

    Perhaps there is another way?

    Thanks for any guidance!
    JP

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Create Query with variable for filename?

    Does this show up as a data connection? If so, there are ways to tinker with the connection string. Basically you split it into an array on the semicolon, replace the part you want, and then merge it back together.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Create Query with variable for filename?

    Dflak - No, it's not a data connection (which I am using on another import for the same project), it's a query... I'm pretty sure the part of the syntax that is messing me up is using the variable strFilename -- because when I leave it with the filename hardcoded, it works just fine.

    Thanks for your time and feedback!

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: Create Query with variable for filename?

    Close:

    Please Login or Register  to view this content.
    Rory

  5. #5
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Create Query with variable for filename?

    rorya - that did the trick...I was trying to add and remove quotations to/from the variable, in the string itself, and wow...that did it perfectly. THANK YOU!

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: Create Query with variable for filename?

    Glad to help.

+ 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. Export to pdf - filename query
    By dantray02 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 01-24-2014, 01:01 PM
  2. [SOLVED] Find if filename exists and update variable within the filename structure
    By Lungfish in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-18-2013, 02:42 AM
  3. Macro to copy from xls( variable filename) to static xls filename
    By gsp77 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2012, 09:33 AM
  4. Code to create a custom .csv filename with version stamp in filename
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-10-2012, 04:07 AM
  5. Replies: 3
    Last Post: 07-09-2012, 03:09 PM
  6. Variable Filename
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-27-2011, 04:10 PM
  7. Converting a Variable Filename to a Constant Filename
    By Magnivy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-15-2006, 01:15 PM
  8. Query Refresh without filename prompt
    By RLang in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2006, 01:30 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