vba in outlook 2007

  • Thread starter mahesh
  • Start date Views 2,170
M

mahesh

#1
Dear Gurus,

Im getting the following error when i run my vba macro in outlook 2007.

Earlier this macro was successfully running in outlook 2003. I've just

migrated from outlook 2003 to outlook 2007

The error message :

Compile error:

User-defined type not defined

at the following line:

Dim oStory As Range

Pls advice, Thanks..

Mahesh
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
#2
The Outlook oject model doesn't know a Range object.

It's always a good idea to use the full object name, for instance

Word.Range, or Excel.Range.

So, check the code and see what library the Range object belongs to, then

add a ref on it via Tools/References.

Best regards

Michael Bauer

Am Fri, 8 Jan 2010 00:06:01 -0800 schrieb mahesh:


> Dear Gurus,

> Im getting the following error when i run my vba macro in outlook 2007.
> Earlier this macro was successfully running in outlook 2003. I've just
> migrated from outlook 2003 to outlook 2007

> The error message :
> Compile error:
> User-defined type not defined

> at the following line:
> Dim oStory As Range

> Pls advice, Thanks..
> Mahesh
 
M

mahesh

#3
Hi Michael,

I proceeded to include the Tools/Reference for Word,Excel,VBA etc...

I now get the following error when i execute the macro in Office 2007:

Run-time error '429':

ActiveX component can't create object

I then click Debug at the Msgbox

Further, when i put the cursor on the following line:

For Each rngStory In ActiveDocument.StoryRanges

it displays this tooltip error that reads:

ActiveDocument.StoryRanges=<Object Variable or With Block variable not set
Following is the code im trying to execute:

Sub a2()

Dim rngStory As Word.Range

For Each rngStory In ActiveDocument.StoryRanges

With rngStory.Find

> Text = "find text"

> Replacement.Text = "I'm found"

> Wrap = wdFindContinue

> Execute Replace:=wdReplaceAll

End With

Next rngStory

End Sub

Am i btw missing any other references.

Thanks,

Mahesh

"Michael Bauer " wrote:



> The Outlook oject model doesn't know a Range object.

> It's always a good idea to use the full object name, for instance
> Word.Range, or Excel.Range.

> So, check the code and see what library the Range object belongs to, then
> add a ref on it via Tools/References.

> > Best regards
> Michael Bauer
>

>

> Am Fri, 8 Jan 2010 00:06:01 -0800 schrieb mahesh:
>
> > Dear Gurus,
> > Im getting the following error when i run my vba macro in outlook 2007.
> > Earlier this macro was successfully running in outlook 2003. I've just
> > migrated from outlook 2003 to outlook 2007
> > The error message :
> > Compile error:
> > User-defined type not defined
> > at the following line:
> > Dim oStory As Range
> > Pls advice, Thanks..
> > Mahesh

> .
>
 
M

mahesh

#4
Sorry, THere was a typo in the above...

ITs NOT word.range

Its just Range


> Sub a2()
> Dim rngStory As Range
> For Each rngStory In ActiveDocument.StoryRanges
> With rngStory.Find
> .Text = "find text"
> .Replacement.Text = "I'm found"
> .Wrap = wdFindContinue
> .Execute Replace:=wdReplaceAll
> End With
> Next rngStory
> End Sub


Does outlook 2007 recognize Range command?

Thanks..

"mahesh" wrote:


> Hi Michael,

> I proceeded to include the Tools/Reference for Word,Excel,VBA etc...

> I now get the following error when i execute the macro in Office 2007:

> Run-time error '429':
> ActiveX component can't create object

> I then click Debug at the Msgbox

> Further, when i put the cursor on the following line:
> For Each rngStory In ActiveDocument.StoryRanges

> it displays this tooltip error that reads:

> ActiveDocument.StoryRanges=<Object Variable or With Block variable not set

> Following is the code im trying to execute:

> Sub a2()
> Dim rngStory As Word.Range
> For Each rngStory In ActiveDocument.StoryRanges
> With rngStory.Find
> .Text = "find text"
> .Replacement.Text = "I'm found"
> .Wrap = wdFindContinue
> .Execute Replace:=wdReplaceAll
> End With
> Next rngStory
> End Sub

> Am i btw missing any other references.
> Thanks,
> Mahesh

> "Michael Bauer " wrote:
>
> > The Outlook oject model doesn't know a Range object.
> > It's always a good idea to use the full object name, for instance
> > Word.Range, or Excel.Range.
> > So, check the code and see what library the Range object belongs to, then
> > add a ref on it via Tools/References.
> > > > Best regards
> > Michael Bauer
> >

> >

> > Am Fri, 8 Jan 2010 00:06:01 -0800 schrieb mahesh:
> >
> > > Dear Gurus,
> > > > Im getting the following error when i run my vba macro in outlook 2007.
> > > Earlier this macro was successfully running in outlook 2003. I've just
> > > migrated from outlook 2003 to outlook 2007
> > > > The error message :
> > > Compile error:
> > > User-defined type not defined
> > > > at the following line:
> > > Dim oStory As Range
> > > > Pls advice, Thanks..
> > > Mahesh

> > .
> >
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
#5
With the ActiveDocument object it becomes clear that it's Word not Excel.

You get the error because ActiveDocument is nothing. Create a variable for

it, and if the code is for an opened email, set the variable to

Application.ActiveInspector.WordEditor, which returns a Word.Document

object.

Best regards

Michael Bauer

Am Mon, 11 Jan 2010 21:52:01 -0800 schrieb mahesh:


> Sorry, THere was a typo in the above...

> ITs NOT word.range

> Its just Range
>
> > Sub a2()
> > Dim rngStory As Range
> > For Each rngStory In ActiveDocument.StoryRanges
> > With rngStory.Find
> > .Text = "find text"
> > .Replacement.Text = "I'm found"
> > .Wrap = wdFindContinue
> > .Execute Replace:=wdReplaceAll
> > End With
> > Next rngStory
> > End Sub


> Does outlook 2007 recognize Range command?

> Thanks..

> "mahesh" wrote:
>
> > Hi Michael,
>

>> I proceeded to include the Tools/Reference for Word,Excel,VBA etc...
>

>
>> I now get the following error when i execute the macro in Office 2007:
>

>> Run-time error '429':
> > ActiveX component can't create object
>

>> I then click Debug at the Msgbox
>

>
>> Further, when i put the cursor on the following line:
> > For Each rngStory In ActiveDocument.StoryRanges
>

>> it displays this tooltip error that reads:
>

>> ActiveDocument.StoryRanges=<Object Variable or With Block variable not


set>
>

>
>> Following is the code im trying to execute:
>

>> Sub a2()
> > Dim rngStory As Word.Range
> > For Each rngStory In ActiveDocument.StoryRanges
> > With rngStory.Find
> > .Text = "find text"
> > .Replacement.Text = "I'm found"
> > .Wrap = wdFindContinue
> > .Execute Replace:=wdReplaceAll
> > End With
> > Next rngStory
> > End Sub
>

>
>> Am i btw missing any other references.
> > Thanks,
> > Mahesh
>

>> "Michael Bauer " wrote:
> >
> >
>>> The Outlook oject model doesn't know a Range object.
> >
>>> It's always a good idea to use the full object name, for instance
> >> Word.Range, or Excel.Range.
> >
>>> So, check the code and see what library the Range object belongs to,


then
> >> add a ref on it via Tools/References.
> >
>>> > >> Best regards
> >> Michael Bauer
> >>

> >>

>>
>>
>>> Am Fri, 8 Jan 2010 00:06:01 -0800 schrieb mahesh:
> >
>>> > Dear Gurus,
> >>>> > Im getting the following error when i run my vba macro in outlook


2007.
> >> > Earlier this macro was successfully running in outlook 2003. I've just
> >> > migrated from outlook 2003 to outlook 2007
> >>>> > The error message :
> >> > Compile error:
> >> > User-defined type not defined
> >>>> > at the following line:
> >> > Dim oStory As Range
> >>>> > Pls advice, Thanks..
> >> > Mahesh
> >> .
> >>
 
M

mahesh

#6
Thank you. Will try it out.

"Michael Bauer " wrote:



> With the ActiveDocument object it becomes clear that it's Word not Excel.

> You get the error because ActiveDocument is nothing. Create a variable for
> it, and if the code is for an opened email, set the variable to
> Application.ActiveInspector.WordEditor, which returns a Word.Document
> object.

> > Best regards
> Michael Bauer
>

>

> Am Mon, 11 Jan 2010 21:52:01 -0800 schrieb mahesh:
>
> > Sorry, THere was a typo in the above...
> > ITs NOT word.range
> > Its just Range
> >
> >> Sub a2()
> >> Dim rngStory As Range
> >> For Each rngStory In ActiveDocument.StoryRanges
> >> With rngStory.Find
> >> .Text = "find text"
> >> .Replacement.Text = "I'm found"
> >> .Wrap = wdFindContinue
> >> .Execute Replace:=wdReplaceAll
> >> End With
> >> Next rngStory
> >> End Sub

> > Does outlook 2007 recognize Range command?
> > Thanks..
> > "mahesh" wrote:
> >
> >> Hi Michael,
> >
> >> I proceeded to include the Tools/Reference for Word,Excel,VBA etc...
> >
> >
> >> I now get the following error when i execute the macro in Office 2007:
> >
> >> Run-time error '429':
> >> ActiveX component can't create object
> >
> >> I then click Debug at the Msgbox
> >
> >
> >> Further, when i put the cursor on the following line:
> >> For Each rngStory In ActiveDocument.StoryRanges
> >
> >> it displays this tooltip error that reads:
> >
> >> ActiveDocument.StoryRanges=<Object Variable or With Block variable not

> set>
> >
> >
> >> Following is the code im trying to execute:
> >
> >> Sub a2()
> >> Dim rngStory As Word.Range
> >> For Each rngStory In ActiveDocument.StoryRanges
> >> With rngStory.Find
> >> .Text = "find text"
> >> .Replacement.Text = "I'm found"
> >> .Wrap = wdFindContinue
> >> .Execute Replace:=wdReplaceAll
> >> End With
> >> Next rngStory
> >> End Sub
> >
> >
> >> Am i btw missing any other references.
> >> Thanks,
> >> Mahesh
> >
> >> "Michael Bauer " wrote:
> >
> >>
> >>> The Outlook oject model doesn't know a Range object.
> >>
> >>> It's always a good idea to use the full object name, for instance
> >>> Word.Range, or Excel.Range.
> >>
> >>> So, check the code and see what library the Range object belongs to,

> then
> >>> add a ref on it via Tools/References.
> >>
> >>> > >>> Best regards
> >>> Michael Bauer
> >>>

> >>>

> >>
> >>
> >>> Am Fri, 8 Jan 2010 00:06:01 -0800 schrieb mahesh:
> >>
> >>> > Dear Gurus,
> >>> >>> > Im getting the following error when i run my vba macro in outlook

> 2007.
> >>> > Earlier this macro was successfully running in outlook 2003. I've just
> >>> > migrated from outlook 2003 to outlook 2007
> >>> >>> > The error message :
> >>> > Compile error:
> >>> > User-defined type not defined
> >>> >>> > at the following line:
> >>> > Dim oStory As Range
> >>> >>> > Pls advice, Thanks..
> >>> > Mahesh
> >>> .
> >>>

> .
>
 

Similar threads

Top