+ Reply to Thread
Results 1 to 5 of 5

How to save file dynamically in My Documents directory which is in D drive?

  1. #1
    Registered User
    Join Date
    12-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    27

    How to save file dynamically in My Documents directory which is in D drive?

    Hi Guys,

    I have some line of code that works best for my machine as I have "My Document" directory in C drive. Now that I have been given a new laptop in which my macro doesn't work because here directory in D drive. Below is the error message:

    Error.png

    When I click on "My Document" folder of my D drive I get this path: D:\UserData\PAREKHKE\Documents. I am running Windows 7 Enterprise.

    How do I tweak the code? Please help I have created a nice macro and everything is working fine except this - driving me crazy

    I appreciate your time!!

    Best,
    Bunty
    Attached Images Attached Images

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: How to save file dynamically in My Documents directory which is in D drive?

    Change the bit of code that says
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    (and please, in future, post your code as text, not as a picture!)
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    12-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: How to save file dynamically in My Documents directory which is in D drive?

    Thanks for the prompt reply Olly, and please accept my apology I would make sure to paste the code as text moving forward.

    I have tried changing it and it gave me run time error saying that "This extension cannot be used with the selected file type." hence I changed the code like below:-

    Please Login or Register  to view this content.
    I think the "Environ" function taking the default directory as C drive which is the problem.

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: How to save file dynamically in My Documents directory which is in D drive?

    That code works for me - albeit with the prompt to remind you that macros will not be saved, using this file type...

    What's the error you are getting, with the modified code?

  5. #5
    Registered User
    Join Date
    12-12-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: How to save file dynamically in My Documents directory which is in D drive?

    The macro worked for you may be because you have "My Document" directory in C drive, in my case it is in D drive (D:\UserData\PAREKHKE\Documents) The Environ function is looking for path in C drive in my case. Below if the error message:

    Run-time error "1004":
    Microsoft excel cannot access the file
    C:\Users\PAREKHKE\Documents\CD339000

+ 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. vba to copy data , create sheet and save it to a specific directory on C drive
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-27-2016, 10:16 AM
  2. [SOLVED] Need to loop a macro to save images to file - but save to user defined directory.
    By superfurry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2015, 07:49 AM
  3. [SOLVED] Macro to save to Network Drive is saving to My Documents
    By MooseAUH in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2014, 07:26 AM
  4. Replies: 0
    Last Post: 01-27-2013, 12:13 PM
  5. Replies: 4
    Last Post: 10-21-2012, 06:00 PM
  6. Replies: 3
    Last Post: 06-11-2009, 07:08 PM
  7. Use VBA to allow you to select a file name from a directory (public drive/server)
    By turnerje in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-27-2005, 03:03 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