+ Reply to Thread
Results 1 to 14 of 14

how do i change the file path for vba worksheets when transfering files to another pc?

  1. #1
    Registered User
    Join Date
    02-09-2016
    Location
    uk
    MS-Off Ver
    2010
    Posts
    38

    how do i change the file path for vba worksheets when transfering files to another pc?

    hello all, i have about 50 macro enabled worksheets and around the same for xlsx and open them through a button system using vba. if i transfer these files to another pc, then i cannot open them in the same way as the file path changes : Workbooks.Open Filename:="c:\users\laboratory\documents\worksheets\worksheets\external mic\imperial digital external mic.xlsx" the blue part obviously need to be changed to accomodate the new pc, so is the a way to put in a variable so it references another sheet/macro to change the first part of the filepath? cheers.
    Last edited by confused monkey; 06-03-2016 at 06:01 AM.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,033

    Re: can this be done in vba?

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Never use Merged Cells in Excel

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,121

    Re: can this be done in vba?

    http://www.excelforum.com/tips-and-t...excel-vba.html

    Please Login or Register  to view this content.
    Or just

    Please Login or Register  to view this content.

    Please note ... Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,121

    Re: can this be done in vba?

    @zbor. Thanks, and sorry. Tried to delete the response myself but you beat me to it

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,033

    Re: can this be done in vba?

    I've just soft delete it so I can restore it once user change a title.
    Don't want to waste your effort.

  6. #6
    Registered User
    Join Date
    02-09-2016
    Location
    uk
    MS-Off Ver
    2010
    Posts
    38

    Re: how do i change the file path for vba worksheets when transfering files to another pc?

    sorry about that. changed now.

  7. #7
    Registered User
    Join Date
    02-09-2016
    Location
    uk
    MS-Off Ver
    2010
    Posts
    38

    Re: can this be done in vba?

    cheers for the response. i'm not too up on the jargon in the code (self taught and struggling). is there anyway you can explain what each line is and where to implement the macro? sorry for being a retard

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,121

    Re: how do i change the file path for vba worksheets when transfering files to another pc?

    Just look at the short example at the end. It gets the my document path and puts it in a string. So use that when you save the file instead of hard coding the whole file path.

  9. #9
    Registered User
    Join Date
    02-09-2016
    Location
    uk
    MS-Off Ver
    2010
    Posts
    38

    Re: how do i change the file path for vba worksheets when transfering files to another pc?

    am i putting this in the button click macro to open the sheet or the sheet itself? i could send an attachment that would better explain if thats any good to you?

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,121

    Re: how do i change the file path for vba worksheets when transfering files to another pc?

    Please Login or Register  to view this content.
    It does rather assume that the rest of the folder structure exists under the My Documents folder.

  11. #11
    Registered User
    Join Date
    02-09-2016
    Location
    uk
    MS-Off Ver
    2010
    Posts
    38

    Re: how do i change the file path for vba worksheets when transfering files to another pc?

    cheers, i can see what it's doing. where do i paste this though? you'll need to use simple terms as i'm a simpleton

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,121

    Re: how do i change the file path for vba worksheets when transfering files to another pc?

    Replace the file name in the Workbooks.Open with the modified file name

  13. #13
    Registered User
    Join Date
    02-09-2016
    Location
    uk
    MS-Off Ver
    2010
    Posts
    38

    Re: how do i change the file path for vba worksheets when transfering files to another pc?

    that works a treat. you sir are an effing genius. thanks a lot for taking the time to help me. have a great weekend and thanks again.

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,121

    Re: how do i change the file path for vba worksheets when transfering files to another pc?

    You're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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