+ Reply to Thread
Results 1 to 10 of 10

VBA code to input data from one workbook to another, run that workbook/return the answer

  1. #1
    Registered User
    Join Date
    07-25-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2007
    Posts
    10

    VBA code to input data from one workbook to another, run that workbook/return the answer

    I have two workbooks, one is has been built up by myself and the second is connected to a thermodynamics program. I was to take the temperature and pressures from my workbook and input them into the workbook which is linked to a thermodynamic program it will then return the fluid properties to that program and then I want to pull these properties out of this workbook and return then to the one I built. I hope this makes sense as I have only been using excel and VBA for about a week or two.

  2. #2
    Forum Contributor
    Join Date
    07-05-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: VBA code to input data from one workbook to another, run that workbook/return the answ

    I have written code very similar to what you need, but I will have a few questions.

    1. Are the two (2) workbooks located in the same folder?
    Click on the * icon if this post has been helpful.

  3. #3
    Registered User
    Join Date
    07-25-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA code to input data from one workbook to another, run that workbook/return the answ

    Yeah I have the second workbook (The one linked to the thermodynamics program) linked as an add-in to the first workbook. The second is saved in C:\programfiles\NIST\Refprop7 and I just have the first workbook (The one I wrote)on my desktop but can easily save it where I have the second workbook. I really appreciate any help or advice you have. what I am trying to do is pull temperatures and pressures I input in the first workbook sent to the second one which will return the fluid properties to the first workbook. the first workbook has a loop built in so will finish calculations then come up with new temperatures and pressures which again will be input into the second workbook. I hope im exxplaining it in an appropriate way its just I havent been using VBA or excel for very long at all

    Thanks again
    Last edited by Cutter; 07-27-2012 at 08:58 AM. Reason: Removed whole post quote

  4. #4
    Forum Contributor
    Join Date
    07-05-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: VBA code to input data from one workbook to another, run that workbook/return the answ

    It would be easiest if they were in the same place. Would it be possible to upload a sample of each file, with some fake data but in the right places so that I can manipulate while writing the code?

  5. #5
    Registered User
    Join Date
    07-25-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA code to input data from one workbook to another, run that workbook/return the answ

    Ok so I will put them in the same folder from here on in. However unless I upload both the workbooks the code is far too long to put up, in my workbook there is 12 sheets and ten modules full of code. They are run on a macro loop which I pasted below, this itself runs up to one hundred so you can see how long the code would be to put up. The code I tried to write was to take the input cell of pressure from my workbook and input this into the second workbook. the second workbook is linked to the thermodynamics programme it hase two cells where the user can enter values and once you hit enter it returns certain results, I want to then take these results and feed tham back into certain cells in my workbook so the calculations can finish correctly.

    Please Login or Register  to view this content.


    ---------- Post added at 07:37 PM ---------- Previous post was at 07:36 PM ----------

    I can upload some of the second code if you want its only one workbook but it it is extremely long winded
    Last edited by Cutter; 07-25-2012 at 10:15 PM. Reason: Added code tags

  6. #6
    Forum Contributor
    Join Date
    07-05-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: VBA code to input data from one workbook to another, run that workbook/return the answ

    We can try it this way. Here is the code I wrote for a similar application:

    Please Login or Register  to view this content.
    You can try and modify this code to fit your needs. If you can't seem to make it work let me know.

  7. #7
    Registered User
    Join Date
    07-25-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA code to input data from one workbook to another, run that workbook/return the answ

    Cheers I really appreciate your help I shall have a look at your code today and tomorrow and try fit it to mine. I really am gratefull for you helping me, thanks again and I will let you know how I get on

  8. #8
    Registered User
    Join Date
    07-25-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA code to input data from one workbook to another, run that workbook/return the answ

    This code works perfectly (Once I addapted it) at sending the cells into the second workbook, and I assume I can just write it in reverse to send the reults back to the first workbook? thanks man... I just have a few questions it only works if it re opens the second workbook is there a way of having them both open? I addapted the this part of the code to have them open it runs fine with no errors and returns transfer completed but the cells arent being input at all?

    Please Login or Register  to view this content.
    Also when I wrote the code in reverse (As in sending reference cells from workbook two back to one (The answers I need)) it returns transfer complete with no buggs however nothin is transfered. did you come accross any of these problems?

    I really appreciate the help thou as other than these problems it works fine and has me on the right path

    ---------- Post added at 03:16 PM ---------- Previous post was at 12:45 PM ----------

    Here is the full code (that returns the message transfer completed and second transfer comlpeted but will not work



    Please Login or Register  to view this content.
    Last edited by Cutter; 07-27-2012 at 08:57 AM. Reason: Added code tags

  9. #9
    Forum Contributor
    Join Date
    07-05-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: VBA code to input data from one workbook to another, run that workbook/return the answ

    First off, you need to add code tags to the bottom code as well. They will get you for that.
    Secondly, I will look into it and let you know what I come up with.

    Question: Are the first and second files always going to stay open together?
    Last edited by Xer2; 07-26-2012 at 11:51 AM.

  10. #10
    Registered User
    Join Date
    07-25-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA code to input data from one workbook to another, run that workbook/return the answ

    Yeah the first and second file should always stay open together, after I get this code working fully for one cell I am goin to try adapt it to work in a loop calculation which the first workbook shall run. Basically having the two workbooks constantly inputting and extracting new data.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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