+ Reply to Thread
Results 1 to 9 of 9

VBA Open File/Run Macro/Close &Save/Open Next File

  1. #1
    Forum Contributor
    Join Date
    08-23-2013
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 365
    Posts
    166

    VBA Open File/Run Macro/Close &Save/Open Next File

    There is a similar thread I found to this one but I can't seem to get it working, keeps saying that the file is already open.

    Looking to go through a folder of files and open/run/save/close each macro:

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    10-10-2015
    Location
    Hoboken, Antwerp, Belgium
    MS-Off Ver
    2010
    Posts
    93

    Re: VBA Open File/Run Macro/Close &Save/Open Next File

    Hi,

    It seems that you open each file, but you don't close it again.
    Greetings,

    Cheetahke

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: VBA Open File/Run Macro/Close &Save/Open Next File

    The probllem is as Cheetahke says file is not closed but. Try adding

    Please Login or Register  to view this content.
    As you seems to operate on the opened workbook I assume you wish to save the changes done to that workbook. But if you are reading data from opened file to a master file then you should keep the opened workbook in it's original state i.e.

    Please Login or Register  to view this content.
    Alf
    Last edited by Alf; 10-21-2015 at 01:27 AM.

  4. #4
    Forum Contributor
    Join Date
    08-23-2013
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 365
    Posts
    166

    Re: VBA Open File/Run Macro/Close &Save/Open Next File

    I am still getting problems with the below code:
    Please Login or Register  to view this content.
    I am getting a sub or fx not defined:

    in the context of:

    Please Login or Register  to view this content.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Open File/Run Macro/Close &Save/Open Next File

    Where is the sub UpdateData actually located?

    Is it in the workbook the code is in or the workbook you are opening?
    If posting code please use code tags, see here.

  6. #6
    Forum Contributor
    Join Date
    08-23-2013
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 365
    Posts
    166

    Re: VBA Open File/Run Macro/Close &Save/Open Next File

    Hi Nor,
    It is in the workbook I am opening.
    So basically I want to open each workbook in a folder (one at a time)>run UpdateData macro>save&close.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Open File/Run Macro/Close &Save/Open Next File

    You'll need to use Application.Run then.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    08-23-2013
    Location
    Alberta, Canada
    MS-Off Ver
    Excel 365
    Posts
    166

    Re: VBA Open File/Run Macro/Close &Save/Open Next File

    Please Login or Register  to view this content.
    So in place of the subroutine?

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Open File/Run Macro/Close &Save/Open Next File

    Yes, that's right.

+ 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. Problem With Open File and Save File With Saveas and then close the File
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-27-2013, 12:53 AM
  2. Replies: 0
    Last Post: 10-02-2013, 01:47 AM
  3. Macro to Open a file, transfer data, save and close
    By tforbes75 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-01-2011, 11:59 AM
  4. Save and Close Open File
    By cmcgath in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-17-2010, 10:35 AM
  5. How to: Open file, format data, save file, close file and repeat.
    By thexeber in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-11-2010, 12:56 PM
  6. Close & save a file at set time only IF the file is open
    By Clivey_UK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-01-2006, 01:19 PM

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