Sunday, April 2, 2017

WorkBooks

'Workbook Object
'Represents a Microsoft Excel workbook.
'Remarks
'
'
'The Workbook object is a member of the Workbooks collection. The Workbooks collection contains all the Workbook objects currently open in Microsoft Excel.
'
'ThisWorkbook property
'The ThisWorkbook property returns the workbook where the Visual Basic code is running. In most cases, this is the same as the active workbook. However, if the Visual Basic code is part of an add-in, the ThisWorkbook property won’t return the active workbook. In this case, the active workbook is the workbook calling the add-in, whereas the ThisWorkbook property returns the add-in workbook.
'
'If you’ll be creating an add-in from your Visual Basic code, you should use the ThisWorkbook property to qualify any statement that must be run on the workbook you compile into the add-in.
'

Option Explicit
'Example WorkBooks
Sub TestWorkBook1()

Workbooks.Add
ActiveWorkbook.SaveAs "C:\Users\Vinay Kumar\Desktop\testWB.xlsx"
ActiveWorkbook.Close

End Sub

Sub TestWorkBook2()

Workbooks.Add.SaveAs Environ("userprofile") & "\Desktop\testWB56.xlsx"
ActiveWorkbook.Close
ActiveWorkbook.Save

End Sub

Sub TestWorkBook3()

Workbooks.Open (Environ("userprofile") & "\desktop\testwb5.xlsx")

End Sub

No comments:

Post a Comment

*INTERVIEW QUESTIONS

* Ques 01. What is the difference between ByVal and ByRef and which is default ? Ans-  ByRef : If you pass an argument by reference when...