Consulting

Results 1 to 6 of 6

Thread: Delete automatically opened workbook

  1. #1

    Delete automatically opened workbook

    With the following code I get information from a .mdb file

        Workbooks.OpenDatabase Filename:="C:\C\SomeFile.MDB", CommandText:=Array( _
            "SomeParams"), CommandType:=xlCmdTable
    The workbook opened by above code needs to be deleted after the following:

    Range("A1", Range("A" & Rows.Count).End(xlUp).Offset(, 16)).Copy
        Windows("AnotherWorkbook.xls").Activate
            Range("A1").Select
        ActiveSheet.Paste
    The workbook name could be anything from Book1, Book2, Book3 etc etc.
    How would I go about this?

    Thank you very much in advance

    Regards
    John

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    Workbooks.OpenDatabase Filename:="C:\C\SomeFile.MDB", CommandText:=Array( _
    "SomeParams"), CommandType:=xlCmdTable
    Set wb = ActiveWorkbook
    [/vba]

    [vba]
    Range("A1", Range("A" & Rows.Count).End(xlUp).Offset(, 16)).Copy
    Windows("AnotherWorkbook.xls").Activate
    Range("A1").Select
    ActiveSheet.Paste
    sh.Close SaveChanges:=False
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Hi Bob.

    Changed
    sh.Close SaveChanges:=False
    to

    wb.Close SaveChanges:=False
    and all is OK.

    Thank you very much

    Regards

    John

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yeah, that would help
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    You were not testing me?

    John

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No, just being sloppy!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •