+ Reply to Thread
Results 1 to 7 of 7

VBA to Save , close and Re-open the workbook again

  1. #1
    Registered User
    Join Date
    06-12-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    86

    VBA to Save , close and Re-open the workbook again

    Dear Team,

    I am new to VBA and trying to develop a code to do following

    (i) to do required computation.

    (ii) Saves the workbook and close the workbook

    (iii) Open the workbook again

    Re-opening is being done to refresh the pivot table.
    Code used to close the workbook has been taken from excelforum itself

    ThisWorkbook.Save
    If Workbooks.Count = 1 Then Application.Quit
    If Workbooks.Count >= 2 Then
    ThisWorkbook.Close SaveChanges:=True
    Application.Quit
    End If

    The VBA is working till closing the workbook, but is not taking command to re-open as the application is already quite and further steps cannot be executed.

    The code tried to open the workbook are used as below -

    (i) 'Workbooks.Open Filename:="ActiveWorkbook.FullName
    (ii) 'Workbooks.Open Filename:="E:\Kamal personal Folder\Excel \VBA Tutorial-learning vba.xlsm"
    (iii) 'Dim MyFile As String
    'MyFile = Application.GetOpenFilename()

    All three are not working

    I want to keep path dynamic so that , wherever it goes, it may identify the path and open itself.

    Is it possible by any way.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA to Save , close and Re-open the workbook again

    Why reopen, you can just refresh the pivot after saving
    TIP, record a macro to refresh the Pivot table, you'll see the code and then you can edit it and put it to use.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    06-12-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: VBA to Save , close and Re-open the workbook again

    Dear Keebellah,

    hmmm... that also will work. But is there any code to open the workbook again after closing it with Vba codes.


    Regards,

    Kamal

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA to Save , close and Re-open the workbook again

    Probably, I don't have it at hand but you can Google.
    I still don't understand why all that just to save and refresh a pivot table

  5. #5
    Forum Contributor
    Join Date
    06-07-2016
    Location
    Manila
    MS-Off Ver
    365
    Posts
    292

    Re: VBA to Save , close and Re-open the workbook again

    Well, if you just want to refresh your pivot table:

    Please Login or Register  to view this content.
    No need to re-open the files.

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: VBA to Save , close and Re-open the workbook again

    That’s what I’ve been trying to say all the time

  7. #7
    Registered User
    Join Date
    06-12-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    86

    [Solved] Re: VBA to Save , close and Re-open the workbook again

    Solved !

    Thanks !

    Kamal Asharaf

+ 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. Open workbook copy&paste, save and close Repeat
    By JPSIMMON in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2016, 12:29 PM
  2. Open/Save/Close Workbook via command button
    By nathan0519 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-31-2015, 11:24 PM
  3. [SOLVED] Macro to open/close/save workbook
    By JonathanB2 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-14-2014, 10:51 AM
  4. Replies: 1
    Last Post: 12-26-2013, 04:55 AM
  5. 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
  6. Open workbook, copy data, save and close error
    By Jessica.Bush in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-01-2012, 12:59 PM
  7. Save an open workbook, then open template workbook and close the saved workbook
    By ondvirg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 10:20 PM

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