+ Reply to Thread
Results 1 to 11 of 11

Reference to External Workbook Objects

  1. #1
    Registered User
    Join Date
    10-22-2009
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    80

    Reference to External Workbook Objects

    Hi all

    I'm having trouble working this around, i use the following code in one of my Workbook sheets.

    Please Login or Register  to view this content.

    Explanation: I dont want the code to go on the Workbook to my clients, i want to have it on my main Workbook and when i press Button1 it will just copy the fields from "Arrival Form.xls" Workbook to my "Main.xlsm" Workbook

    What happens after several trys its gives me object error and range error

    Any help would be welcome, thanks in advance
    Last edited by Rage; 12-21-2009 at 08:49 AM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Copy from other Workbook

    Hi Rage what happens if you save the xlsm as xls?
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    10-22-2009
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Copy from other Workbook

    Well the file format doesnt have anything to do with it, i can use xls or xlsm and still works out the same.

    Want i want it to do is, with that code on my main it gets the objects that i refer but those objects are in a diferent workbook.


    Main(Workbook) = Code

    Copy from ->

    Arrival Form(Workbook) = Objects


    This way i can prevent users changing my code.

  4. #4
    Registered User
    Join Date
    10-22-2009
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Copy from other Workbook

    Up up and away

  5. #5
    Registered User
    Join Date
    10-22-2009
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Copy from other Workbook

    Please can i get some help over here ????

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Copy from other Workbook

    I'm a little lost as why the code is in the clients workbook
    Why dont you place the code in a module?
    can you please explain a little more?

  7. #7
    Registered User
    Join Date
    10-22-2009
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Copy from other Workbook

    Hi Pike,

    Well since im new to VBA i started to build this like you saw it.
    And now as you may notice i want to change the way i started.

    I think my explanation of what i want may not be the best.

    I want the main workbook to reference the objects on the clientes workbook

    The coding i had is the one i posted and yeah it was working on the clients workbook

    I think this is the way to put it, the problem is that i dont know how to make the code refer to another workbook objects.

    All the help would be welcome

  8. #8
    Forum Contributor
    Join Date
    09-22-2009
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Office 2003 / Office 2007
    Posts
    114

    Re: Reference to External Workbook Objects

    This is not to difficult to do:

    Please Login or Register  to view this content.
    This will open the book and set a reference to it. Then you can do things like:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-22-2009
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Reference to External Workbook Objects

    But how do i use that reference as u say with a Range on this


    For example
    Please Login or Register  to view this content.
    Can i use ?

    Please Login or Register  to view this content.
    Last edited by Rage; 12-21-2009 at 10:49 AM.

  10. #10
    Forum Contributor
    Join Date
    09-22-2009
    Location
    Indianapolis, Indiana
    MS-Off Ver
    Office 2003 / Office 2007
    Posts
    114

    Re: Reference to External Workbook Objects

    Whenever you do something in VBA, by default it references whatever the active book / sheet is. So when you do something like this:

    Please Login or Register  to view this content.
    You are really doing this:

    Please Login or Register  to view this content.
    If instead you want to refer to a book that is not the active book, you can refer to it directly:

    Please Login or Register  to view this content.
    This defines precisely which workbook and worksheet you would like to work with, and will work with any currently open workbook. This gets a bit cumbersome so you usually set a reference to that.

    Please Login or Register  to view this content.
    Now you could use the following instead of typing all of that out:

    Please Login or Register  to view this content.
    In this example, we have set MyShortcut to refer specifically to the sheet named "Sheet1" in the workbook MyTest.xls.

  11. #11
    Registered User
    Join Date
    10-22-2009
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Reference to External Workbook Objects

    Well marzuk i got it to work with all your explanation.

    But probably there is a easy way of doing this

    Please Login or Register  to view this content.

+ 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