Kill a Workbook

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Maninder Karir
    New Member
    • Dec 2006
    • 15

    Kill a Workbook

    Hi,

    Im having trouble deleting a workbook using VBA. What i want is to open a workbook called "xxxxx waiting", make some modification and then save it as readonly but as a "xxxxx complete". I then want to delete the old workvook "xxxxx waiting"

    I though i had it cracked but it doesnt seem to work. Ive put the code below if someone could help.

    Thanks in advance

    Private Sub Save_Click()

    ReqNum = Worksheets("che micals").Range( "D2")

    With ActiveWorkbook
    .SaveAs Filename:="Z:\R eq\" & ReqNum & "Complete", _
    FileFormat:=xlN ormal, Password:="", WriteResPasswor d:="", _
    ReadOnlyRecomme nded:=True, CreateBackup:=F alse

    End With

    Kill "Z:\Req\" & ReqNum & "Waiting"

    End Sub
    Manny
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    I don't think that you can kill yourself. That would be dangerous. :D You'll need another program to open the workbook, save as, close, and kill.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Can you be a bit more specific than "doesn't work"? What does happen?

      Comment

      • fplesco
        New Member
        • Jul 2007
        • 82

        #4
        Originally posted by Maninder Karir
        Hi,

        Im having trouble deleting a workbook using VBA. What i want is to open a workbook called "xxxxx waiting", make some modification and then save it as readonly but as a "xxxxx complete". I then want to delete the old workvook "xxxxx waiting"

        I though i had it cracked but it doesnt seem to work. Ive put the code below if someone could help.

        Thanks in advance

        Private Sub Save_Click()

        ReqNum = Worksheets("che micals").Range( "D2")

        With ActiveWorkbook
        .SaveAs Filename:="Z:\R eq\" & ReqNum & "Complete", _
        FileFormat:=xlN ormal, Password:="", WriteResPasswor d:="", _
        ReadOnlyRecomme nded:=True, CreateBackup:=F alse

        End With

        Kill "Z:\Req\" & ReqNum & "Waiting"

        End Sub
        Manny

        Hi there -

        You might miss the extension of the file

        Try this:
        Code:
        Kill "Z:\Req\" & ReqNum & "Waiting.xls"
        Have a nice day!

        Comment

        • fplesco
          New Member
          • Jul 2007
          • 82

          #5
          Originally posted by Maninder Karir
          Hi,

          Im having trouble deleting a workbook using VBA. What i want is to open a workbook called "xxxxx waiting", make some modification and then save it as readonly but as a "xxxxx complete". I then want to delete the old workvook "xxxxx waiting"

          I though i had it cracked but it doesnt seem to work. Ive put the code below if someone could help.

          Thanks in advance

          Private Sub Save_Click()

          ReqNum = Worksheets("che micals").Range( "D2")

          With ActiveWorkbook
          .SaveAs Filename:="Z:\R eq\" & ReqNum & "Complete", _
          FileFormat:=xlN ormal, Password:="", WriteResPasswor d:="", _
          ReadOnlyRecomme nded:=True, CreateBackup:=F alse

          End With

          Kill "Z:\Req\" & ReqNum & "Waiting"

          End Sub
          Manny

          Hi there -

          You might miss the extension of the file and the space between the ReqNum and Waiting:

          Try this:
          Code:
          Kill "Z:\Req\" & ReqNum & " Waiting.xls"   ' put a single SPACE before Waiting
          Have a nice day!

          Comment

          • Maninder Karir
            New Member
            • Dec 2006
            • 15

            #6
            Originally posted by fplesco
            Hi there -

            You might miss the extension of the file

            Try this:
            Code:
            Kill "Z:\Req\" & ReqNum & "Waiting.xls"
            Have a nice day!

            Thanks worked a treat!!!!

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by fplesco
              ... You might miss the extension of the file and the space between the ReqNum and Waiting ...
              Thanks again, fplesco.

              I'm curious though - are you sure about the space? I've always used Format$() function when printing or concatenating numbers, specifically to prevent the insertion of the extra space. Can never remember though, whether it's before or after the number. (I guess I should go and check.)

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by Killer42
                ... I've always used Format$() function when printing or concatenating numbers, specifically to prevent the insertion of the extra space. Can never remember though, whether it's before or after the number. (I guess I should go and check.)
                Well, I just set up this elaborate testing scenario...
                Code:
                ? 5;"h";6;"f";7
                which produced the output " 5 h 6 f 7 and confirmed that printing, at least, leaves a space before the number.

                But of course (and I'm sure you know where this is heading) a quick test with this code...[CODE=vb]Dim A As String
                A = 5 & "h" & 6 & "f" & 7
                Debug.Print A[/CODE]...produced "5h6f7", thus refuting my "extra space" theory. Obviously I've been using Format unnecessarily. Slightly annoying, but I guess it's good that I know better now.

                Comment

                Working...