j6g
09-21-2014, 02:22 PM
Hello Team,
Greetings!! This is my first attempt at VBA!! I am reading Excel 2007 VBA Programming for Dummies by Mr. John Walkenbach. Excellent read for a complete novice like me!!
However, I am trying to figure out exactly what is going on the with the code below. Just wanted to write a basic VBA code to make sure that I am understanding what I am reading!!
When I am typing the following code the error pops out as follows:
Sub myfirstmac()
Application.Workbooks("Book1.xls").Worksheets("Sheet1").Range("A1").Value
End Sub
The corresponding error:
Run-time error '438' Object doesn't support this property or method!!
However, when I am modifying the code above with the one maintained below, the code just runs perfectly!!
Sub myfirstmac()
x = Application.Workbooks("Book1.xls").Worksheets("Sheet1").Range("A1").Value
MsgBox x
End Sub
Can some one help me as to why is this happening?? Why am I getting the run time error, in the first case??
Any help, will be highly appreciated!!
Regards,
Jai
Greetings!! This is my first attempt at VBA!! I am reading Excel 2007 VBA Programming for Dummies by Mr. John Walkenbach. Excellent read for a complete novice like me!!
However, I am trying to figure out exactly what is going on the with the code below. Just wanted to write a basic VBA code to make sure that I am understanding what I am reading!!
When I am typing the following code the error pops out as follows:
Sub myfirstmac()
Application.Workbooks("Book1.xls").Worksheets("Sheet1").Range("A1").Value
End Sub
The corresponding error:
Run-time error '438' Object doesn't support this property or method!!
However, when I am modifying the code above with the one maintained below, the code just runs perfectly!!
Sub myfirstmac()
x = Application.Workbooks("Book1.xls").Worksheets("Sheet1").Range("A1").Value
MsgBox x
End Sub
Can some one help me as to why is this happening?? Why am I getting the run time error, in the first case??
Any help, will be highly appreciated!!
Regards,
Jai