Consulting

Results 1 to 4 of 4

Thread: Application.close information required

  1. #1

    Application.close information required

    Hello Everyone,

    Can anyone let me know how to close a chosen, opened workbook among all the other opened workbooks?

    Actually i am opening a workbook(DATA1.xls) in my macro(calculator.xls) to get the data needed for my calculation. After copying the data from DATA1.xls, i want to close that workbook.

    The workbook name can change so i cannot use workbooks(DATA1.xls).close always.
    I am using a variable "DATA" while opening that workbook, is there any way to use this to close the workbook?

    DATA = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a Master list file")

    Thanks in advance;
    Regards,
    Prashanth.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Set a public workbook variable when you open the workbook

    [vba]

    DATA = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a Master list file")
    Set wbData = Workbooks.open(DATA)

    'do stuff

    wbData.Close
    [/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
    Quote Originally Posted by xld
    Set a public workbook variable when you open the workbook

    [vba]

    DATA = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a Master list file")
    Set wbData = Workbooks.open(DATA)

    'do stuff

    wbData.Close
    [/vba]
    Thanks for the early reply xld,

    But the above code did not work for some reason.
    i tried something along your liines and it worked
    Data = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select the Master list file")
    Workbooks.Open Filename:=MasterList
    wb1 = ActiveWorkbook.Name
    do stuff
    Workbooks(wb1).Close

    Regards,
    Prashanth

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Add [VBA]Dim wbData as Workbook[/VBA] at the start of XLD's code
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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