+ Reply to Thread
Results 1 to 4 of 4

Changing file paths in macro automatically

  1. #1
    Forum Contributor
    Join Date
    12-02-2013
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    112

    Question Changing file paths in macro automatically

    HI,

    I have a file named input1.xlsm in folder C:\values\extra\input\input1\input1.xlsm.

    And there is a command button named "SUBMIT" in cell "E6" of "sheet1".

    I would like to copy-paste the file "input1.xlsm" to a different folder, which is "C:\values\extra\input\input2\input1.xlsm"

    But the problem is that the file paths that are present in the command button "SUBMIT" wont't change when i copy-paste "input1.xlsm to the folder input2.

    Is there a way so, that the filepaths in the macro also change after COPY-PASTE?

    cheers

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Changing file paths in macro automatically

    Instead of explicitly stating the filepath, you can use commands that auto-detect it.

    "Application.ActiveWorkbook.Path" is just the folder the file is in
    "Application.ActiveWorkbook.FullName" is the folder and file all in one
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Forum Contributor
    Join Date
    12-02-2013
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    112

    Re: Changing file paths in macro automatically

    Hi,

    Set myData1 = Workbooks.Open("C:\values\extra\input\input1\VALUES1.xlsm")
    myData1.Save
    myData1.Close


    is required to be changed to :

    Set myData1 = Workbooks.Open("C:\values\extra\input\input2\VALUES1.xlsm")
    myData1.Save
    myData1.Close

    after pasting the file inpu1.xlsm to folder input2.

    But it remains constant, any ideas about the problem?

    thanks

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Changing file paths in macro automatically

    You don't need to state the filepath at all.

    Application.ActiveWorkbook.Path is wherever the workbook is. No matter where you paste it.


    Please Login or Register  to view this content.

+ 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. Changing MSWord OLE Paths
    By ptmuldoon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-01-2014, 04:55 PM
  2. How to delete links(paths) from the fomulas after add-on changing?
    By sphinx_ps in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-28-2013, 02:16 PM
  3. Excel changing external link paths! HELP!
    By LangerXXV in forum Excel General
    Replies: 0
    Last Post: 12-15-2011, 11:05 PM
  4. Changing Paths
    By Exsilium in forum Excel General
    Replies: 1
    Last Post: 03-08-2011, 12:24 PM
  5. Problem with a macro changing paths
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-19-2006, 06:35 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