I am trying to use the following code to open a worksheet but get the runtime error 438 for line "DestBook.Anlysheet.Select".
Cannot understand where I am going wrong. Please help.
Cannot understand where I am going wrong. Please help.
Code:
Dim strFName As String
Dim DestBook As Workbook, SourceBook As Workbook
Dim DestCell As Range, TinR As Range
Dim RetVal As Boolean
Dim TINdataIndex As Long, AnlysheetIndex As Long
Dim Anlysheet As Worksheet
'code starts from here'
Set DestBook = ActiveWorkbook
'To open the source workbook'
For Each Anlysheet In DestBook.Worksheets(Array("Y02A", "Y01A", "Y02B", "Y01B"))
DestBook.Anlysheet.Select
Range("D10").Select
Set DestCell = ActiveCell
strFName = Anlysheet(AnlysheetIndex).Range("B2").Value
'this variable contains the workbook name and path
If FileExists(strFName) Then
'does it exist?
If Not BookOpen(Dir(strFName)) Then Workbooks.Open Filename:=strFName
'if its not already open, open it
Else
MsgBox "The file does not exist!"
End If
Set SourceBook = ActiveWorkbook