+ Reply to Thread
Results 1 to 5 of 5

Running macro from different workbook

  1. #1
    Registered User
    Join Date
    10-08-2008
    Location
    Hallandale
    Posts
    44

    Running macro from different workbook

    Can somebody tell me how to fix this ?

    I have this macro but it only works in this workbook “Obrisi.xls”
    I think I need to change the row “Windows("Obrisi.xls").Activate” to be able to do it in the workbook that I have open at the time rather then the workbook in which macro is saved.

    I know I can change the code every time I run it but the point is to take currently open workbook and paste there what is needed.

    I hope I’m clear with the explanation.


    Please Login or Register  to view this content.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    Assign the current workbook name (short version) to a variable at the commencement of your code and use that to switch windows

    Please Login or Register  to view this content.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello koklok,

    I clean your macro code up for you. You don't need to change the directory to a workbook if it is in a different directory. You only need to include the full path.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-08-2008
    Location
    Hallandale
    Posts
    44
    Leith Ross,

    The code that you provided me doesn’t work as it should:
    If I open a new work (for example: Book1) and run the macro, macro opens a new workbook (Book2) and runs the macro in the new workbook.
    And gives me a error message same as below

    If I save the empty work book and try to run it from there I get the message:
    “Run-time error ‘438’: Object doesn’t support this property or method”
    and following is highlighted as error.

    Range (“A1”). Paste

    Any idea what the problem is?

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello koklok,

    Here is the revised macro. You may need to change the worksheet and workbook names.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

+ 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