+ Reply to Thread
Results 1 to 4 of 4

Copy sheet to new Workbook (ReNaming + Macro)

Hybrid View

  1. #1
    Registered User
    Join Date
    06-09-2016
    Location
    Norway, Oslo
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Question Copy sheet to new Workbook (ReNaming + Macro)

    Hi everyone,

    I have created a rudimentary excel workbook with macros, and the main idea behind it is to fill out a form, and then you can click a button which runs a macro module; which in turn saves the current sheet to a server, and automatically sends an email to the Administrators - warning them that a new form is ready to be published.

    Sub Module3()
    Application.ScreenUpdating = False
    
    Worksheets("LO FORM").Copy
    With ActiveWorkbook
         .SaveAs Filename:=("**SERVERPATH**") & "\LOFORM.xlsx", FileFormat:=xlOpenXMLWorkbook
         .Close SaveChanges:=False
         
    Application.ScreenUpdating = True
    
    End With 'At this point the Mail macro runs'
    How ever the problem I'm having is that I do not know how to make the file rename it self, as of now only one user can save the file, and if another tries he will only get a warning that the file already exists, and you can only overwrite or cancel the process. So my question is, is there a way I can tell the macro to rename the file if another file with the same name already exists?

    Thanks in advance,
    Last edited by MicroDude; 06-09-2016 at 04:24 AM. Reason: Renaming title to be more descriptive

  2. #2
    Registered User
    Join Date
    05-22-2016
    Location
    United Kingdom
    MS-Off Ver
    2010
    Posts
    15

    Re: Copy sheet to new Workbook (ReNaming + Macro)

    Hello MicroDude

    How many forms get created each day? You could code the macro to add the date to the file name, and then if multiple forms are created each day you can then also add the current 'time' to the filename.

    This would create somewhat unique file names. Failing that the function below will check if the files exists, just pass it the filename (fname) and define the serverpath variable
    Function CheckExists(fname As String) As Boolean
    Dim TestStr As String
    Dim fpath As String
    
    fpath = Worksheets("Filepaths & Filenames").Range("D4").Value
    
    TestStr = ""
    On Error Resume Next
    TestStr = Dir(fpath & "\" & fname & ".xlsm")
    
    On Error GoTo 0
    If TestStr = "" Then
            'MsgBox "File doesn't exist"
            CheckExists = False
    Else
            'MsgBox "File exist"
            CheckExists = True
    End If
    
    End Function
    Caleeco
    www.excelwtf.com - Helping solve those WTF moments

  3. #3
    Registered User
    Join Date
    06-09-2016
    Location
    Norway, Oslo
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Re: Copy sheet to new Workbook (ReNaming + Macro)

    Hi Caleeco,

    Thanks for the quick answer, I really appreciate it. I've been trying to implement this code into my original piece, but it just doesn't want to work. Do I need to create a new module and insert the function, and then link the original (COPY) module to run that function as a check? And if so how? I'd gladly appreciate any help!

    Thanks again!
    Last edited by MicroDude; 06-09-2016 at 07:08 AM. Reason: Spelling error

  4. #4
    Registered User
    Join Date
    06-09-2016
    Location
    Norway, Oslo
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Re: Copy sheet to new Workbook (ReNaming + Macro)

    Shameless self-bump..

+ 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] Copy sheet from another workbook based on ComboBox names of the Workbook and sheet
    By igormigor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2016, 10:07 AM
  2. Replies: 5
    Last Post: 12-18-2014, 04:20 PM
  3. [SOLVED] Renaming and Saving Workbook based on Sheet name or cell value
    By shinobi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-19-2013, 08:20 AM
  4. [SOLVED] Copy Values From Each Workbook in Folder to a Single Sheet in New Workbook +Workbook names
    By Arsham24 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-21-2012, 07:42 PM
  5. How to copy a hidden sheet in a workbook and paste it into a new worksheet and renaming it
    By kvs.somashekhar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2012, 08:20 AM
  6. Move/copy and renaming sheet
    By luke_p in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-14-2009, 05:58 AM
  7. prevent a specific sheet from copy and renaming of workbook
    By JohnSeito in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-30-2008, 02:05 AM

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