vba in outlook 2007

M

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

Michael Bauer [MVP - Outlook]

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 - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


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

mahesh

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
 
M

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..
 
M

Michael Bauer [MVP - Outlook]

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 - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


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

mahesh

Thank you. Will try it out.

Michael Bauer said:
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 - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


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

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top