+ Reply to Thread
Results 1 to 2 of 2

Running VBA to save worksheet as a new file but need to delete original -help

  1. #1
    Registered User
    Join Date
    08-01-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    9

    Running VBA to save worksheet as a new file but need to delete original -help

    HI all
    I'm still learning and getting better through tutorials, through this forum and also through exploring Excel VBA.

    I have a scenario in which I need some help please. In my main calculation workbook I have some input sheets, and then some output sheets. For one of the output sheets I've written some VBA to copy the values (not the formulas) and then save as a new workbook/sheet. Now I'd like to include a routine to delete the original file.

    As I understand it, seeing as I've taken suggestions on each of the steps from various sources, the first part of the code copies the source worksheet just as values and then renames. The second part does the copy and save as work, allowing the user to set a filename. I want to delete the specially created "EaaS PLI and Pricing Form" from the original worksheet but equally need to ensure that the sheet copies to a new file.

    Can this even be done with a single click/code? I've been trying to work out where in the code this event should happen, and keep failing! Here's my current code :

    Sub Copy_Sheet_Without_Code()

    Sheets("PLI Form").Cells.Copy
    Sheets.Add.Name = "EaaS PLI and Pricing Form"
    Sheets("EaaS PLI and Pricing Form").Cells.PasteSpecial Paste:=xlPasteAll
    ThisWorkbook.Sheets("EaaS PLI and Pricing Form").Copy
    Dim fname
    fname = InputBox("Enter Opportunity Numer")
    fname = fname & " EaaS PLI Form.xlsm"
    ActiveWorkbook.SaveAs fname, FileFormat:=52

    End Sub


    Thanks as always
    Last edited by jars104; 01-23-2020 at 06:27 AM.

  2. #2
    Registered User
    Join Date
    08-01-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Running VBA to save worksheet as a new file but need to delete original -help

    I think I've found a way around it by thinking laterally. I checked to see if I could use a "move" operator (sounds like the Sade song - for those of a certain age!), which creates the same workflow. My code now looks like this :

    Sub Copy_Sheet_Without_Code()


    Sheets("PLI Form").Cells.Copy
    Sheets.Add.Name = "EaaS PLI and Pricing Form"
    Sheets("EaaS PLI and Pricing Form").Cells.PasteSpecial Paste:=xlPasteAll
    ThisWorkbook.Sheets("EaaS PLI and Pricing Form").Move
    Dim fname
    fname = InputBox("Enter Opportunity Numer")
    fname = fname & " EaaS PLI Form.xlsm"
    ActiveWorkbook.SaveAs fname, FileFormat:=52



    End Sub

+ 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. Replies: 8
    Last Post: 12-02-2019, 03:42 PM
  2. Save As/Save Copy As workbook to a new file name/path without closing the original
    By jennis7242 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-27-2019, 04:57 AM
  3. Script/macro to save a copy as tab delimited text file and then close original file
    By Merlin803 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2015, 01:34 PM
  4. [SOLVED] Save worksheet to separate file with no macro buttons & no connections to original
    By kopapa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-04-2013, 05:53 AM
  5. Replies: 1
    Last Post: 09-05-2013, 02:39 PM
  6. rename current file save and delete original
    By valve79 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-13-2006, 05:17 PM
  7. Replies: 1
    Last Post: 08-15-2005, 06:05 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