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

andymalan

Board Regular
Joined
Feb 22, 2017
Messages
128
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
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
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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:
Upvote 0
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
 
Upvote 0
Dear Tim_Excel_
user-offline.png
,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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,223,967
Messages
6,175,674
Members
452,666
Latest member
AllexDee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top