Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default newbie question

Hi,

I'm pretty new to excel vba. In an attempt to learn I'm playing around with
code samples I've taken from MSDN just to see how they work and the results
returned. The problem is when I use suggested code from the MSDN site I'm
receiving errors without explanation.

I'm try to get a grip on application methods and events etc. An example of
an error I'm getting is as follows:

Suggested code:

' create a new range in a worksheet
thisapplication.names.add("Hello","=Sheet1!$a$1")

so I place this in a sub as follows:

Sub Test()
thisapplication.names.add("Hello","=Sheet1!$a$1")
End Sub


When I run this I get an error "Compile Error: Expected: ="

What am I doing wrong here. This is very frustrating as this is just one
example of suggested code returning an error. Should I be approaching this
some other way.

Any suggestions appreciated.

Paul


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default newbie question

Use:

ActiveWorkbook.Names.Add "Hello", "=Sheet1!$A$2"

- Mangesh


"PC" <paulm dot c @ iol dot ie wrote in message
...
Hi,

I'm pretty new to excel vba. In an attempt to learn I'm playing around

with
code samples I've taken from MSDN just to see how they work and the

results
returned. The problem is when I use suggested code from the MSDN site I'm
receiving errors without explanation.

I'm try to get a grip on application methods and events etc. An example of
an error I'm getting is as follows:

Suggested code:

' create a new range in a worksheet
thisapplication.names.add("Hello","=Sheet1!$a$1")

so I place this in a sub as follows:

Sub Test()
thisapplication.names.add("Hello","=Sheet1!$a$1")
End Sub


When I run this I get an error "Compile Error: Expected: ="

What am I doing wrong here. This is very frustrating as this is just one
example of suggested code returning an error. Should I be approaching this
some other way.

Any suggestions appreciated.

Paul




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default newbie question

Two things

you don't need the brackets
thisapplication has to be defined

Try

Application.Names.Add "Hello", "=Sheet1!$a$1"

--
HTH

Bob Phillips

"PC" <paulm dot c @ iol dot ie wrote in message
...
Hi,

I'm pretty new to excel vba. In an attempt to learn I'm playing around

with
code samples I've taken from MSDN just to see how they work and the

results
returned. The problem is when I use suggested code from the MSDN site I'm
receiving errors without explanation.

I'm try to get a grip on application methods and events etc. An example of
an error I'm getting is as follows:

Suggested code:

' create a new range in a worksheet
thisapplication.names.add("Hello","=Sheet1!$a$1")

so I place this in a sub as follows:

Sub Test()
thisapplication.names.add("Hello","=Sheet1!$a$1")
End Sub


When I run this I get an error "Compile Error: Expected: ="

What am I doing wrong here. This is very frustrating as this is just one
example of suggested code returning an error. Should I be approaching this
some other way.

Any suggestions appreciated.

Paul




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default newbie question

Thanks for the reply Bob, that works fine.

My questiobn now though is in what context would the code I mentioned below
be correct (It must be correct in some context as it was cut and pasted from
MSDN).

Also how would I define "thisapplication" as you suggested below.

Again thanks for your help

Paul

"Bob Phillips" wrote in message
...
Two things

you don't need the brackets
thisapplication has to be defined

Try

Application.Names.Add "Hello", "=Sheet1!$a$1"

--
HTH

Bob Phillips

"PC" <paulm dot c @ iol dot ie wrote in message
...
Hi,

I'm pretty new to excel vba. In an attempt to learn I'm playing around

with
code samples I've taken from MSDN just to see how they work and the

results
returned. The problem is when I use suggested code from the MSDN site I'm
receiving errors without explanation.

I'm try to get a grip on application methods and events etc. An example
of
an error I'm getting is as follows:

Suggested code:

' create a new range in a worksheet
thisapplication.names.add("Hello","=Sheet1!$a$1")

so I place this in a sub as follows:

Sub Test()
thisapplication.names.add("Hello","=Sheet1!$a$1")
End Sub


When I run this I get an error "Compile Error: Expected: ="

What am I doing wrong here. This is very frustrating as this is just one
example of suggested code returning an error. Should I be approaching
this
some other way.

Any suggestions appreciated.

Paul






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default newbie question

like so

thisapplication = Excel.Application
Set myName = thisapplication.names.add("Hello","=Sheet1!$a$1")

--
HTH

Bob Phillips

"PC" <paulm dot c @ iol dot ie wrote in message
...
Thanks for the reply Bob, that works fine.

My questiobn now though is in what context would the code I mentioned

below
be correct (It must be correct in some context as it was cut and pasted

from
MSDN).

Also how would I define "thisapplication" as you suggested below.

Again thanks for your help

Paul

"Bob Phillips" wrote in message
...
Two things

you don't need the brackets
thisapplication has to be defined

Try

Application.Names.Add "Hello", "=Sheet1!$a$1"

--
HTH

Bob Phillips

"PC" <paulm dot c @ iol dot ie wrote in message
...
Hi,

I'm pretty new to excel vba. In an attempt to learn I'm playing around

with
code samples I've taken from MSDN just to see how they work and the

results
returned. The problem is when I use suggested code from the MSDN site

I'm
receiving errors without explanation.

I'm try to get a grip on application methods and events etc. An example
of
an error I'm getting is as follows:

Suggested code:

' create a new range in a worksheet
thisapplication.names.add("Hello","=Sheet1!$a$1")

so I place this in a sub as follows:

Sub Test()
thisapplication.names.add("Hello","=Sheet1!$a$1")
End Sub


When I run this I get an error "Compile Error: Expected: ="

What am I doing wrong here. This is very frustrating as this is just

one
example of suggested code returning an error. Should I be approaching
this
some other way.

Any suggestions appreciated.

Paul








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
Real Newbie newbie question Dave New Users to Excel 0 January 10th 07 07:55 PM
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
newbie question vapor77 New Users to Excel 5 February 4th 06 12:08 AM
Newbie question Doh New Users to Excel 5 December 16th 04 09:31 PM
Newbie Question Random Excel Programming 2 August 3rd 03 03:25 PM


All times are GMT +1. The time now is 08:50 PM.

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

About Us

"It's about Microsoft Excel"