![]() |
VBA Tutorial problem
Hi,
I'm taking this tutorial http://homepages.ius.edu/WCLANG/vbnotes/vbex2.htm and cannot run the macro for the "Hello World!" procedure. I get a compile error with when i try to run this: - the yellow cursor pointing at the defined "Sub Hello World()" - "CurrentSheet =" is selected Here is the code from my sheet1 object: Sub HelloWorld() Set CurrentSheet = Application.ActiveSheet CurrentSheet.Cells(2, 5) = "Hello World!" End Sub Any help would be appreciated. I am running Excel97 (I know, I know, its old) -- TIA AFJr |
VBA Tutorial problem
Sounds like you have Option Explicit in your modules, which is a good
practice, so try Sub HelloWorld() Dim CurrentSheet As Worksheet Set CurrentSheet = Application.ActiveSheet CurrentSheet.Cells(2, 5) = "Hello World!" End Sub -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "AFJr" wrote in message ... Hi, I'm taking this tutorial http://homepages.ius.edu/WCLANG/vbnotes/vbex2.htm and cannot run the macro for the "Hello World!" procedure. I get a compile error with when i try to run this: - the yellow cursor pointing at the defined "Sub Hello World()" - "CurrentSheet =" is selected Here is the code from my sheet1 object: Sub HelloWorld() Set CurrentSheet = Application.ActiveSheet CurrentSheet.Cells(2, 5) = "Hello World!" End Sub Any help would be appreciated. I am running Excel97 (I know, I know, its old) -- TIA AFJr |
VBA Tutorial problem
Thanks Bob, that was it!
I though I might need to dimension CurrentSheet but didn't know why and didn't know what to dimension it to. I remember reading in some book about Option Explicit, I'll have to go back and hunt it down. Thanks for your help! -- AFJr "Bob Phillips" wrote: Sounds like you have Option Explicit in your modules, which is a good practice, so try Sub HelloWorld() Dim CurrentSheet As Worksheet Set CurrentSheet = Application.ActiveSheet CurrentSheet.Cells(2, 5) = "Hello World!" End Sub -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "AFJr" wrote in message ... Hi, I'm taking this tutorial http://homepages.ius.edu/WCLANG/vbnotes/vbex2.htm and cannot run the macro for the "Hello World!" procedure. I get a compile error with when i try to run this: - the yellow cursor pointing at the defined "Sub Hello World()" - "CurrentSheet =" is selected Here is the code from my sheet1 object: Sub HelloWorld() Set CurrentSheet = Application.ActiveSheet CurrentSheet.Cells(2, 5) = "Hello World!" End Sub Any help would be appreciated. I am running Excel97 (I know, I know, its old) -- TIA AFJr |
VBA Tutorial problem
Option Explicit is a module setting that means that you HAVE to declare all
variables, otherwise you get the error. It is a good practice, because if you leave to implicit variable declaration, you get problems. For instance, look at myValue= 125 MsgBox myValu * 1.175 The MsgBox will show zero, because although a variable myValue was loaded with 125, the code then (mistakenly) used a variable myValu, the e was omitted, which has no value. If the variable is declared, it will show as a compile error, the code doesn't run and produce wrong results. -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "AFJr" wrote in message ... Thanks Bob, that was it! I though I might need to dimension CurrentSheet but didn't know why and didn't know what to dimension it to. I remember reading in some book about Option Explicit, I'll have to go back and hunt it down. Thanks for your help! -- AFJr "Bob Phillips" wrote: Sounds like you have Option Explicit in your modules, which is a good practice, so try Sub HelloWorld() Dim CurrentSheet As Worksheet Set CurrentSheet = Application.ActiveSheet CurrentSheet.Cells(2, 5) = "Hello World!" End Sub -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "AFJr" wrote in message ... Hi, I'm taking this tutorial http://homepages.ius.edu/WCLANG/vbnotes/vbex2.htm and cannot run the macro for the "Hello World!" procedure. I get a compile error with when i try to run this: - the yellow cursor pointing at the defined "Sub Hello World()" - "CurrentSheet =" is selected Here is the code from my sheet1 object: Sub HelloWorld() Set CurrentSheet = Application.ActiveSheet CurrentSheet.Cells(2, 5) = "Hello World!" End Sub Any help would be appreciated. I am running Excel97 (I know, I know, its old) -- TIA AFJr |
All times are GMT +1. The time now is 01:31 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com