If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > create a copy of an opened excel file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-03-04, 06:05
gtb gtb is offline
Registered User
 
Join Date: Aug 2004
Posts: 1
create a copy of an opened excel file

can anyone tell me how to create a copy of an opened excel file...i have tried "filecopy" but this can be used only if the excel file is closed...
Reply With Quote
  #2 (permalink)  
Old 08-03-04, 10:54
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi

Here is one way.

This routine
1 saves the existing file (to save unsaved data)
2 saves the file with a new name (ie a copy)
3 opens the origional file
4 closes the copy

Code:
Sub SaveCopy()
    Dim ThisBookName As String
    Dim ThisBookPath As String
    Dim NewBookName As String
    
    'REMEMBER FILE NAME AND PATH
    ThisBookName = ThisWorkbook.Name
    ThisBookPath = ThisWorkbook.Path
    
    'SAVE EXISTING WORKBOOK
    ThisWorkbook.Save
    
    'SET NAME OF COPY FILE
    NewBookName = "Copy of " & ThisBookName
    
    'DELETE ANY COPY OF THE COPY IF IT EXISTS
    If Dir(ThisBookPath & "\" & NewBookName) <> "" Then Kill ThisBookPath & "\" & NewBookName
    
    'SAVE BOOK AS A COPY
    ActiveWorkbook.SaveAs ThisBookPath & "\" & NewBookName
    
    'OPEN ORIGIONAL WORKBOOK
    Workbooks.Open FileName:=ThisBookPath & "\" & ThisBookName
    
    'CLOSE NEW COPY OF WORKBOOK
    Workbooks(NewBookName).Close
End Sub
There could well be a better (built in function?) but I havn't found it yet if there is one.

HTH

MTB
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On