+ Reply to Thread
Results 1 to 8 of 8

How to open,save and close another workbook from the current workbook using macro?

  1. #1
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Post How to open,save and close another workbook from the current workbook using macro?

    Hi All,

    I am able to open but not save and close another workbook from the current workbook using macro.

    This is the code that i am using.

    Please Login or Register  to view this content.
    Please help me to modify the code.

    Regards
    Kumar

  2. #2
    Registered User
    Join Date
    06-11-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: How to open,save and close another workbook from the current workbook using macro?

    Dear Ravi,



    Create a Worksheet variable
    assign the workbook to this variable
    replace the path in below code it will work.



    Sub hhgg()
    Dim x As Workbook
    Set x = Application.Workbooks.Open("C:\Documents and Settings\Md.aejaz\Desktop\WORKING Sync Repot MOC6")
    Application.Workbooks(x.Name).Close
    End Sub


    please rate if u are satisfied with this post by selecting the star from below.

  3. #3
    Registered User
    Join Date
    12-15-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: How to open,save and close another workbook from the current workbook using macro?

    I think its just that you don't need the filepath in your save and close instructions:


    Please Login or Register  to view this content.
    Good luck!
    If I helped you today please rate me

  4. #4
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: How to open,save and close another workbook from the current workbook using macro?

    Sorry guys,

    A mistake is happened from my side i have posted my question wrongly.

    When i am opening another workbook,I need to save and close the existed workbook.

    This is how i want.

    Please help me in this.

    Regards
    Kumar

  5. #5
    Registered User
    Join Date
    12-15-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: How to open,save and close another workbook from the current workbook using macro?

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: How to open,save and close another workbook from the current workbook using macro?

    Hi Imvk99,

    If i save and close the file in the begin itself ,How the next code lines will work in the macro.

    Hope you understand the problem.

    This is how my code will look like

    Please Login or Register  to view this content.
    Regards
    Kumar

  7. #7
    Registered User
    Join Date
    12-15-2011
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: How to open,save and close another workbook from the current workbook using macro?

    Apologies, I edited it wrong. Your code is really close. If you know the names of "First" and "Second" then you can just hardcode in the names and put the macro in a module in "first". But if you want this to run without it closing when "first" closes, just make a master file that stays open while doing all of this and save it to a module in there. If you want this to run over and over again for "third" and "fourth" etc, let me know and we can work on that.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-21-2012
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: How to open,save and close another workbook from the current workbook using macro?

    Thanks for the reply.

    Any how i got the solution.

    Please Login or Register  to view this content.
    Actually with this code i am able open second file and closing the "first" file.
    Now again from the "Second" file, I can open the "first" file and close the "Second" file(Because i know that is first file ,I am hard coding).

    Here i have a problem.

    I can open "the" second file from any of the "first" file(Eg: First,First1,First2,First3.....etc)
    In my "first" files,I am not using it's name any where.But my target is to get "second" file.So i can achieve this thing with any of the file by hard coding the "second" file name.
    For to avoid the hard coding the "first" files
    how to identify the previous file from which file the "second" file is open and from here i want to redirect to the previous "first" file.

    Please see the attached image.
    Dynamical.PNG

    Regards
    Kumar

+ 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