Results 1 to 6 of 6

Thread: questions regarding macros created on computer 1 to use on computer 2
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Feb 2018
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    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

  2. #2
    Board Regular Tim_Excel_'s Avatar
    Join Date
    Jul 2016
    Posts
    512
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    4 Thread(s)

    Default Re: questions regarding macros created on computer 1 to use on computer 2

    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 by Tim_Excel_; Mar 21st, 2019 at 03:36 AM.
    Always make a backup of your data before trying out any code

    Before you ask why my code is not working: have you checked if the references are correct? Are you referring to the correct Workbook/-sheet?

    Use [CODE] tags when pasting code in your posts

  3. #3
    New Member
    Join Date
    Feb 2018
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: questions regarding macros created on computer 1 to use on computer 2

    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

  4. #4
    Board Regular Tim_Excel_'s Avatar
    Join Date
    Jul 2016
    Posts
    512
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    4 Thread(s)

    Default Re: questions regarding macros created on computer 1 to use on computer 2

    Not a problem, hope you manage to make it work.
    Always make a backup of your data before trying out any code

    Before you ask why my code is not working: have you checked if the references are correct? Are you referring to the correct Workbook/-sheet?

    Use [CODE] tags when pasting code in your posts

  5. #5
    New Member
    Join Date
    Feb 2018
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: questions regarding macros created on computer 1 to use on computer 2

    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

  6. #6
    Board Regular Tim_Excel_'s Avatar
    Join Date
    Jul 2016
    Posts
    512
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    4 Thread(s)

    Default Re: questions regarding macros created on computer 1 to use on computer 2

    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.
    Always make a backup of your data before trying out any code

    Before you ask why my code is not working: have you checked if the references are correct? Are you referring to the correct Workbook/-sheet?

    Use [CODE] tags when pasting code in your posts

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •