questions regarding macros created on computer 1 to use on computer 2


Board Regular
greetings oh learned people (seriously).
I have created a macro enabled excel sheet named "Data", within this file is a macro to read and copy data from another workbook named "Drw", and paste it to sheet1 of Data. Everything works well on my computer,(comp1), but when I try to run it on comp2 it does not copy from the wb Drw.

The problem is that in the version running on (comp1) it inserts the full pathway to the file Drw, and retains that info. When trying to run on comp2, it uses the same pathway, and because the path is different it stops running.

Is there any way to make the pathway universal for any computer?

Your help, as is always the case, is much valued and appreciated.
Best regards


Well-known Member
It's unclear to me what you're asking, but I have a hunch that the root of your problems is that the files the macro refers to are located in different folders because the two PC's do not use a shared folder.

A couple of ways to tackle this:

1. The paths are the same except for the username, which is different for both machines: Environ("Username") will return you the Windows username as a string, which you will be able to use in the path string

2. There are only 2 (or a small number of) machines and the files are always in a set folder on these machines: you could loop through a pre-defined number of addresses and check whether the files exist in these folders. This is not a pretty solution, as simply moving the files to a folder not covered in the code will break the programme.

Using FileDialog to have the user select the right files: opens the known-to-all file explorer. Requires the user to know about the files and where they are located.

4. Looping through a main folder and its sub-folders to look for the files needed using a recursive function. Neat method, doesn't require user interference and the files could be placed anywhere within a large scope. Look at this SO thread

Good luck
Last edited:


Board Regular
Hello Tim, thanks for your prompt reply. Yes, both files Drw and Data reside in a folder named Dataconfig and always placed in desktop/documents. I will look at your suggestion "SO Thread".
thanks very much


Board Regular
Dear Tim_Excel_
,I have not been successful with the previous info and include the code i cobbled together thus far
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=[DrawingData.xlsx]Page1!RC[3]" (###is there some code i can insert before this line to find whatever computer filepath is?)


Well-known Member
First of all, read this page that will help you avoiding select and activate. That is bad practice.

I'm not sure what you mean by "computer filepath". If you mean to find where the file is located on the machine, you could look into any of the four methods I mentioned earlier.
I feel like you're unsure what to do yourself, so I would advise you to read into the matter and get more familiar with VBA.

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...