+ Reply to Thread
Results 1 to 11 of 11

mapping user defined Path & FileName using VBA

  1. #1
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    mapping user defined Path & FileName using VBA

    Dear experts
    I have the following vba which exports worksheet data to my desktop. Path and the filename are hard coded in the macro but there may be instances when end users may need to change the path and the name of the output file.
    I have defined the same path in cell $D$2 in another worksheet (say Sheet 6) with the file name in cell $D$3. Furthermore to make the output files unique I want to have them date/time stamped so I have specified this in $D$4
    Please could you help modify the following code that would help achieve the desired results.

    Thank you in advance
    D
    Please Login or Register  to view this content.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: mapping user defined Path & FileName using VBA

    Like this, though I'd be tempted to use named ranges rather than cell references

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: mapping user defined Path & FileName using VBA

    Thx Kyle123

    Unfortunately I have a run-time error '1004':
    Method 'SaveAs' of object@_ workbook failed.

    Any idea?

    D

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: mapping user defined Path & FileName using VBA

    I need a bit more to go on than that. What's the resulting full fine name and path?

  5. #5
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: mapping user defined Path & FileName using VBA

    Hi there..

    I have the following values in Sheet6 but will be renamed it to the actual name but for this example, call it TEMPS

    Cell D2 = Export PATH: C:\Documents and Settings\" & Environ("UserName") & "\Desktop\
    Cell D3 = File Name: SPD_Other
    Cell D4 = Date & Time 25/05/2016 11:18

    D

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: mapping user defined Path & FileName using VBA

    You can't write VBA in a worksheet cell. It has to be a proper path

  7. #7
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: mapping user defined Path & FileName using VBA

    Hi

    Cell D2 had the path i.e. C:\Documents and Settings\" & Environ("UserName") & "\Desktop\ for now and user may set it to another path when folder are created
    Cell D3 contains the file name called SPD_Other
    Cell D4 has date and time of 25/05/2016 11:18

    Does this clarify the matter
    D

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: mapping user defined Path & FileName using VBA

    No, it doesn't. Again, you cannot write via in worksheet cell and expect it to work:

    This:
    & Environ("UserName") &

    is VBA, you need a proper file path:
    C:\Documents and Settings\kyle\Desktop\

  9. #9
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: mapping user defined Path & FileName using VBA

    yes. & Environ("UserName") would translate to who the user will be

    d

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: mapping user defined Path & FileName using VBA

    Ok, I'm going to leave this thread. You don't understand the point I'm making and I'm not quite sure how else to explain it.

    Hopefully someone else will help you

  11. #11
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: mapping user defined Path & FileName using VBA

    Thx Kyle for you help so far.

    have a great day
    D

+ 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. Auto save IE file download dialog box in a user defined path
    By sugaprasad in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-27-2014, 05:21 AM
  2. User defined variables in a path reference
    By CaddyMatt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-23-2012, 02:08 PM
  3. Link Filename To User Defined Cells
    By swordswinger710 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2010, 02:08 PM
  4. Find filename, path, document size, filename length and path length?
    By Laneyboggs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2010, 08:01 PM
  5. Replies: 0
    Last Post: 04-14-2010, 10:42 AM
  6. Path for File Saving Defined by USER
    By crapmind in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-21-2007, 09:58 AM
  7. vlookup path not working in UDF (User Defined Function)
    By miagovino in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2007, 01:16 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