Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default 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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial William Wolfe[_2_] Charts and Charting in Excel 0 February 1st 10 04:40 PM
Try this new excel tutorial Mr.Cools Links and Linking in Excel 0 August 5th 06 02:05 PM
VBA tutorial Ken Excel Programming 2 October 28th 04 06:45 PM
VBA tutorial Microsoft Excel Programming 3 September 27th 03 02:49 AM
Tutorial Available Dhiraj Ramakrishnan Excel Programming 0 August 4th 03 04:28 PM


All times are GMT +1. The time now is 04:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"