+ Reply to Thread
Results 1 to 3 of 3

having trouble in executing macro from other workbook

  1. #1
    Registered User
    Join Date
    06-09-2008
    Posts
    7

    having trouble in executing macro from other workbook

    Hi All,

    With the solution mentioned below, I am able to execute the macro correctly in any other workbook. However the problem that I run into is that the output is not correct. But when I execute the macro on any worksheet in the same file, the output works fine correctly. I do not know what is so special about the workbook that contains the macro which lets it handle everything correctly. I had basically taken a uniqueitem lookup function developed by one of the members of the forum and used it and that does not seem to function correctly in the new workbook. Any ideas as to what could be the problem.

    The attachment description is following:
    1) 5x7.xls: contains the macros which work fine for any worksheet in this workbook.
    2) template_results.xls: Contains the file on which I am trying to run the macro from 5x7.xls workbook and the output csv file is not correct since the uniqueitem lookup function did not work correctly.

    When I try to copy the contents of template_results.xls in 5x7.xls and run the macro from 5x7.xls file, I can get the correct output csv files in the format that I want. However when I execute the macro in template_results.xls file, the output csv file does not get created correctly.

    Any help would be greatly appreciated.

    Thanks,

    Anshul
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Your code does not reference the workbook containing the data so it will worlk on the one that contains the code. You need to refernce the correct workbook

    Please Login or Register  to view this content.
    Then make sure that you refernce the ranges & sheets correctly, e.g.

    Application.ScreenUpdating = False

    Please Login or Register  to view this content.
    Some other points;
    You switch off screenupdating, but don't switch it back on.

    Your code needs major tidying up, you don't need to Activate or Select sheets and ranges.

    You duplicate some actions which is unnecessary - Activate Sheet(1) twice, loop throgh the sheets twice whne you could probably loop once & perform both tasks together.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-09-2008
    Posts
    7
    Hello Roy,

    Thanks for the help. However I want the code that I have in 5x7.xls workbook to work for any workbook. Is it possible to modify the code somehow that it can work on any other workbook.

    As for looping through the same sheet twice and screen updating turning off, I had got the code from one of the post in the forum to create a worksheet to a .csv file. I don't really understand each and every step of that code and hence just left as it is. If you can tell me how to avoid looping through the same sheet twice that would be great.

    I thought the reason for having activating sheets is because I am working on multiple worksheets and for code to work correctly, I need to activate it. Please correct me if I am wrong.

    Thanks for all the help.

    Anshul

+ 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