+ Reply to Thread
Results 1 to 4 of 4

close and open a Workbook with a macro button click

  1. #1
    Registered User
    Join Date
    02-25-2014
    Location
    Southampton
    MS-Off Ver
    Excel 2003
    Posts
    49

    Unhappy close and open a Workbook with a macro button click

    Hi there I've been trying to code a macro to save a workbook on close. and then open a workbook on My Documents and update data.

    E.G.
    Book1; data is inputted to cells.
    Click button

    on button click
    close document
    save changes
    open Book2
    update data links

    This is the VB code I have so far;

    Private Sub CommandButton1_Click()

    ActiveWorkbook.Save
    ActiveWindow.Close
    'Refers to Book1
    Workbooks.Open Filename:= _
    "C:\Users\Documents\Book2.xls", _
    UpdateLinks:=0

    Windows("Book2").Activate
    End Sub

    However when I run the macro it only closes the first sheet and does not open the second.
    Please help.

  2. #2
    Forum Contributor
    Join Date
    12-10-2013
    Location
    Mississippi, United States
    MS-Off Ver
    2016
    Posts
    120

    Re: close and open a Workbook with a macro button click

    The issues is once the book closes the macro stops so you have to open the other workbook befroe tou close so try this:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-25-2014
    Location
    Southampton
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: close and open a Workbook with a macro button click

    Thanks for the tip however I books 1 and 2 are linked. I want the data inputted to Book1 to be so bed and then Book2 to be opened and linked cells updated.

    Sent from my GT-I9300 using Tapatalk

  4. #4
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Vancouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    604

    Re: close and open a Workbook with a macro button click

    As above... open other workbook first, then close. You can't run a macro when the book that contains the macro is closed.

    Please Login or Register  to view this content.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to open,save and close another workbook from the current workbook using macro?
    By ravikumar00008 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-15-2012, 10:42 AM
  2. Macro to close/open data validation workbook
    By catccc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2010, 08:20 AM
  3. Macro to close workbook open in IE?
    By martin.mcgarry in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2010, 02:13 PM
  4. Macro to detect if workbook is open Getting close!
    By LAWDAWG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-20-2009, 12:26 AM
  5. Replies: 2
    Last Post: 02-06-2007, 08:26 AM

Tags for this Thread

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