+ Reply to Thread
Results 1 to 15 of 15

Use a macro in one workbook to change another workbook?

  1. #1
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Arrow Use a macro in one workbook to change another workbook?

    Hello,

    I have designed a simple userform with a button that fires a macro. This macro creates multiple copies of workbook and save them in another folder.

    As a part of this macro I want to open the copy, replace the data in two tabs with real values, delete the remaining tabs, save and close.

    Can this be done?

    Cheers
    Last edited by scubadiver007; 03-02-2011 at 11:03 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Use a macro in one workbook to change another workbook?

    Could this not be doen when you create the new workbook?

  3. #3
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Use a macro in one workbook to change another workbook?

    Good idea, but how would I do that?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Use a macro in one workbook to change another workbook?

    You need to explain more fully
    Hope that helps.

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

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Use a macro in one workbook to change another workbook?

    What else would you like to know?

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Use a macro in one workbook to change another workbook?

    What your code does, probably see the code

  7. #7
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Use a macro in one workbook to change another workbook?

    This my first real attempt at doing some major VBA coding so please don't be too hard on me! I hope it makes sense but it does work perfectly fine.

    Years_combo is the first combo box
    Combobox1 is the second combo box




    Please Login or Register  to view this content.
    Last edited by davesexcel; 02-28-2011 at 08:00 PM. Reason: Code tags required

  8. #8
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Use a macro in one workbook to change another workbook?

    cheers for the code tags.

    So can anyone help?

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Use a macro in one workbook to change another workbook?

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  10. #10
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Use a macro in one workbook to change another workbook?

    ok,

    I have attached a simplified version. Press the button on 'sheet 1' and then press 'run report'.

    It will save separate copies based on the information in columns A and B.

    The code for opening the copy has been commented out.

    When the copy has been saved, I want to

    replace the information in the blue tabs with real values
    Delete the remaining tabs.
    Save the copy
    Close it

    start the process again


    I have 56 separate files to create so you can imagine I want to achieve this.
    Attached Files Attached Files

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Use a macro in one workbook to change another workbook?

    You have potential problems with your code - you don't state the sheet to use in the code, so Range(whatever) will be on whichever sheet is active at the time.

    Also, you don't need to select sheets & ranges, this will only slow your code.

    By real values do you mean replace formulas with values?
    Last edited by royUK; 03-01-2011 at 08:01 AM.

  12. #12
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Use a macro in one workbook to change another workbook?

    As I said, I am an absolute beginner at this.

    Yes, I do want to replace formulas with real values.

  13. #13
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Use a macro in one workbook to change another workbook?

    So can anyone help?

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Use a macro in one workbook to change another workbook?

    See if this works, it replaces your run code on the userform

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    02-23-2011
    Location
    Hampshire, England
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Use a macro in one workbook to change another workbook?

    Thanks for that. I have 112 copies to create so this is fab. It was probably easier than I imagined it to be.

    I read my first post and realised I wasn't being very clear. I want to replace the formulas and delete the remaining tabs in the copy, not the master file.



    Please Login or Register  to view this content.




    Now I have a remaining question: How can I turn off

+ 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