+ Reply to Thread
Results 1 to 6 of 6

[SOLVED] delete workbook from one location and save workbook to new locatio

  1. #1
    Damien
    Guest

    [SOLVED] delete workbook from one location and save workbook to new locatio

    I need to be able to save a workbook to a new location and delete the same
    workbook from the old location, if not delete then move the file to another
    folder.
    I am able to save a file using a named range but with my code I can't seem
    to be able to delete.
    I am currently trying with the following code:

    Sub DeletethenSaveFile()

    Dim Range As String
    Set Proj = Sheets("Form").Range("$F$10")
    DeleteFile "Blah Blah Blah" & Range("Proj") & "2.xls"
    MsgBox "The requested file has been deleted"
    ThisWorkbook.SaveCopyAs "Blah Blah Blah" & Range("Proj") & "2.xls"
    MsgBox "Your file has been saved to it's new location"

    End Sub

    Please help! D

  2. #2

    Re: delete workbook from one location and save workbook to new locatio

    Hi Damien,
    May be you can try this :
    Sub DeletethenSaveFile()
    Dim Range As String, Addr as string, Proj as string
    Proj = Sheets("Form").Range("$F$10")
    Addr = "Blah Blah Blah" & Range(Proj) & "2.xls"
    MsgBox "The requested file has been deleted"
    ThisWorkbook.SaveCopyAs "Blah Blah Blah" & Range("Proj") & "2.xls"
    Kill Addr 'To kill or delete old file after copying it
    MsgBox "Your file has been saved to it's new location"
    End Sub


  3. #3
    Damien
    Guest

    Re: delete workbook from one location and save workbook to new loc

    Cheers, The Kill function works great, it also works with my code when I
    knock out the Dim and Set and replace DeleteFile with Kill.

    Kind Regards, D

    "[email protected]" wrote:

    > Hi Damien,
    > May be you can try this :
    > Sub DeletethenSaveFile()
    > Dim Range As String, Addr as string, Proj as string
    > Proj = Sheets("Form").Range("$F$10")
    > Addr = "Blah Blah Blah" & Range(Proj) & "2.xls"
    > MsgBox "The requested file has been deleted"
    > ThisWorkbook.SaveCopyAs "Blah Blah Blah" & Range("Proj") & "2.xls"
    > Kill Addr 'To kill or delete old file after copying it
    > MsgBox "Your file has been saved to it's new location"
    > End Sub
    >
    >


  4. #4

    Re: delete workbook from one location and save workbook to new loc

    Hi Damien,
    please note that Kill is not bring your file to Recycle bin, so you
    can't restore them after Kill.

    You can use API function call to send file to Recycle bin.

    Thanks,

    halim


    Damien menuliskan:
    > Cheers, The Kill function works great, it also works with my code when I
    > knock out the Dim and Set and replace DeleteFile with Kill.
    >



  5. #5
    Damien
    Guest

    Re: delete workbook from one location and save workbook to new loc

    Hi Halim,

    Thanks a million, I need to delete permanently to stop multiple dupications
    on our servers,

    Kind Regards, D

    "[email protected]" wrote:

    > Hi Damien,
    > please note that Kill is not bring your file to Recycle bin, so you
    > can't restore them after Kill.
    >
    > You can use API function call to send file to Recycle bin.
    >
    > Thanks,
    >
    > halim
    >
    >
    > Damien menuliskan:
    > > Cheers, The Kill function works great, it also works with my code when I
    > > knock out the Dim and Set and replace DeleteFile with Kill.
    > >

    >
    >


  6. #6
    Ron de Bruin
    Guest

    Re: delete workbook from one location and save workbook to new locatio

    Another option is to use the VBA name function
    See
    http://www.rondebruin.nl/folder.htm



    --
    Regards Ron de Bruin
    http://www.rondebruin.nl



    "Damien" <[email protected]> wrote in message news:[email protected]...
    >I need to be able to save a workbook to a new location and delete the same
    > workbook from the old location, if not delete then move the file to another
    > folder.
    > I am able to save a file using a named range but with my code I can't seem
    > to be able to delete.
    > I am currently trying with the following code:
    >
    > Sub DeletethenSaveFile()
    >
    > Dim Range As String
    > Set Proj = Sheets("Form").Range("$F$10")
    > DeleteFile "Blah Blah Blah" & Range("Proj") & "2.xls"
    > MsgBox "The requested file has been deleted"
    > ThisWorkbook.SaveCopyAs "Blah Blah Blah" & Range("Proj") & "2.xls"
    > MsgBox "Your file has been saved to it's new location"
    >
    > End Sub
    >
    > Please help! D




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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