+ Reply to Thread
Results 1 to 2 of 2

Keeping file open and saving a copy

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2014
    Location
    Albany, NY
    MS-Off Ver
    Office 2010
    Posts
    91

    Keeping file open and saving a copy

    I am not even sure that the base functionality of Excel can do this, BUT I am hopeful. My conundrum is this: I am looping over a file deleting rows based on a given variable. if a cell value does not match the given variable then the row that cell lives in is deleted. My problem is the File is 250MB (HUGE) and it takes a long time to open. Is there a way to keep the original file open, make the deletions and save it, all while keeping the original in tact and able to be reused for the next variable in the loop?

    My guess is a hard "No", but there are smarter people then I, out there.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,489

    Re: Keeping file open and saving a copy

    Hi there,

    The following code will save a copy of the workbook which contains this routine, as an Excel workbook with whatever filename is specified in the SaveAs dialog box:

    
    
    Option Explicit
    
    
    Sub SaveCopyOfThisWorkbook()
    
        Const sFILE_FILTER  As String = "Excel Files (*.xlsx), *.xlsx"
    
        Dim vNewFileName    As Variant
        Dim sNewFileName    As String
        Dim iErrorNo        As Long
    
        vNewFileName = Application.GetSaveAsFilename(FileFilter:=sFILE_FILTER)
    
        If vNewFileName <> False Then
    
            sNewFileName = CStr(vNewFileName)
    
            On Error Resume Next
                ThisWorkbook.SaveCopyAs Filename:=sNewFileName
                iErrorNo = Err.Number
            On Error GoTo 0
    
            If iErrorNo = 0 Then
    
                  MsgBox "The file """ & sNewFileName & """ has been saved", vbInformation
    
            Else: MsgBox "An error occurred - the copy workbook has NOT been saved", _
                          vbExclamation
            End If
    
        End If
    
    End Sub

    The copy workbook will be saved as an Excel workbook (i.e. macro-free).

    An error message will be displayed if (for whatever reason) the copy file fails to save successfully.


    If you wish to save the copy workbook as a Macro-Enabled workbook the FileFilter statement should be changed as follows:

    
        Const sFILE_FILTER  As String = "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm"

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

+ 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. [SOLVED] Keeping the .txt file open.
    By mellowtang in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-06-2015, 06:09 AM
  2. [SOLVED] SaveAs a Worksheet to another file/folder while keeping the original open/active
    By DJBittner in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-10-2015, 01:23 PM
  3. [SOLVED] SaveAs a Worksheet to another file/folder while keeping the original open/active
    By DJBittner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2014, 12:13 PM
  4. Save sheet as CSV while keeping original file open?
    By gjwilson1216 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2014, 02:34 PM
  5. [SOLVED] How to Copy Column A from File 1 to Column D of File 2 without keeping File 1 open
    By eggcel in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-12-2013, 02:38 AM
  6. [SOLVED] open variably named file, copy/paste data into consolidation file, open next file in list
    By sllawrence1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:49 PM
  7. Saving file to same path as open file
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-19-2007, 04:57 AM

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