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

andymalan

Board Regular
Joined
Feb 22, 2017
Messages
78
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
Andy
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Tim_Excel_

Well-known Member
Joined
Jul 12, 2016
Messages
512
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.

3.
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:

andymalan

Board Regular
Joined
Feb 22, 2017
Messages
78
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
 

andymalan

Board Regular
Joined
Feb 22, 2017
Messages
78
Dear Tim_Excel_
,I have not been successful with the previous info and include the code i cobbled together thus far
Sheets("Sheet1").Select
Windows("ConfigureData.xlsm").Activate
Application.CutCopyMode = False
Range("A1").Select
ActiveCell.FormulaR1C1 = "=[DrawingData.xlsx]Page1!RC[3]" (###is there some code i can insert before this line to find whatever computer filepath is?)
Range("A1").Select
Selection.Copy
Range("B1:F1").Select
ActiveSheet.Paste
 

Tim_Excel_

Well-known Member
Joined
Jul 12, 2016
Messages
512
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,426
Messages
5,528,690
Members
409,830
Latest member
KT50

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top