Monday, September 20, 2010

Workbooks Handling

Create new Workbooks form VBA

Set newBook = Workbooks.Add
    With newBook
        .Title = "List of members"
        .Subject = "New member"
        .SaveAs filename:="Association.xls"
    End With

Add a new Workbooks
Dim wb As Workbook
Set wb = Application.Workbooks.Add

Save a new Workbooks as ".xls"
wb.SaveAs "NewWorkbook"

Close and delete a new Workbooks
wb.Close
VBA.Kill "NewWorkbook.xls"

Open existing Workbooks
Set wb = Application.Workbooks.Open("MyBook.xls")

Set wb = Application.Workbooks.Open(ThisWorkbook.Path & "\MyBook.xls")   'open from the same existing Workbooks

Close a Workbooks
ThisWorkbook.Close True  'True indicate savechange Yes
ThisWorkbook.Close False  'True indicate savechange No
ThisWorkbook.Close True, "Copy of " & ThisWorkbook.Name ' Save as others

Workbooks.Close   'Close All

No comments:

Post a Comment

Please add if your have better information.