Create macro in Outlook 2007

K

Kevinsm

In Outlook 2003 I was able to use a macro I had created in Word to insert the
day, date, and time at the beginning of a new email. Outlook 2007 has no
"macro-record" function and my attempt to import a similar macro I created in
Word 2007 has failed ... when I run it, it results in an error message and I
have no clue how to debug. Any counsel?
 
K

Kevinsm

Right, thanks Michael, it was a macro created in Word and then able to be
used in Outlook 2003 since Word was the message editor ... evidently no
longer the case.

The code is:
Sub DT()
'
' DT Macro
'
'
Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
End Sub

Thanks for your help!
 
M

Michael Bauer [MVP - Outlook]

Not tested but this might work. Add a reference to Word's library
(Tools/References) and insert this at the beginning of your code:

Dim Document as Word.Document
Dim Selection as Word.Selection

Set Document=Application.ActiveInspector.WordEditor
Set Selection=Document.ActiveWindow.Selection

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 18:44:01 -0700 schrieb Kevinsm:
 
K

Kevinsm

I made the change you suggested and I am now getting the following error
message:
[Microsoft Visual Basic]
Compile error:
User-defined type not defined

By the way following your suggestion, the code now is:
Sub DT()
'
' DT Macro
'
'
Dim Document As Word.Document
Dim Selection As Word.Selection

Set Document = Application.ActiveInspector.WordEditor
Set Selection = Document.ActiveWindow.Selection

Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
End Sub
 
M

Michael Bauer [MVP - Outlook]

Did you add a ref to 'Microsoft Word x Object Library'?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 23:26:00 -0700 schrieb Kevinsm:
I made the change you suggested and I am now getting the following error
message:
[Microsoft Visual Basic]
Compile error:
User-defined type not defined

By the way following your suggestion, the code now is:
Sub DT()
'
' DT Macro
'
'
Dim Document As Word.Document
Dim Selection As Word.Selection

Set Document = Application.ActiveInspector.WordEditor
Set Selection = Document.ActiveWindow.Selection

Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
End Sub


Michael Bauer said:
Not tested but this might work. Add a reference to Word's library
(Tools/References) and insert this at the beginning of your code:

Dim Document as Word.Document
Dim Selection as Word.Selection

Set Document=Application.ActiveInspector.WordEditor
Set Selection=Document.ActiveWindow.Selection
Am Tue, 10 Jul 2007 18:44:01 -0700 schrieb Kevinsm:
InsertAsField:=
_ CalendarType:=wdCalendarWestern,
_
 
K

Kevinsm

Danke, nein ... I'll research how to do that when I get a moment and let you
know how it works.

Michael Bauer said:
Did you add a ref to 'Microsoft Word x Object Library'?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 23:26:00 -0700 schrieb Kevinsm:
I made the change you suggested and I am now getting the following error
message:
[Microsoft Visual Basic]
Compile error:
User-defined type not defined

By the way following your suggestion, the code now is:
Sub DT()
'
' DT Macro
'
'
Dim Document As Word.Document
Dim Selection As Word.Selection

Set Document = Application.ActiveInspector.WordEditor
Set Selection = Document.ActiveWindow.Selection

Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
End Sub


Michael Bauer said:
Not tested but this might work. Add a reference to Word's library
(Tools/References) and insert this at the beginning of your code:

Dim Document as Word.Document
Dim Selection as Word.Selection

Set Document=Application.ActiveInspector.WordEditor
Set Selection=Document.ActiveWindow.Selection
Am Tue, 10 Jul 2007 18:44:01 -0700 schrieb Kevinsm:

Right, thanks Michael, it was a macro created in Word and then able to be
used in Outlook 2003 since Word was the message editor ... evidently no
longer the case.

The code is:
Sub DT()
'
' DT Macro
'
'
Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:=
_
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern,
_
InsertAsFullWidth:=False
End Sub

Thanks for your help!

:



Outlook never had a macro recorder, probably you're talking about Word.
What's the code?
Am Mon, 9 Jul 2007 22:48:00 -0700 schrieb Kevinsm:

In Outlook 2003 I was able to use a macro I had created in Word to
insert
the
day, date, and time at the beginning of a new email. Outlook 2007 has
no
"macro-record" function and my attempt to import a similar macro I
created
in
Word 2007 has failed ... when I run it, it results in an error message
and
I
have no clue how to debug. Any counsel?
 
K

Kevinsm

After brief research of 'Microsoft Word 2007 Object Library', I can't see
where or how to add a reference. Word 2007 doesn't have Tools/References in
the same way the earlier version did ... any help?

Michael Bauer said:
Did you add a ref to 'Microsoft Word x Object Library'?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 23:26:00 -0700 schrieb Kevinsm:
I made the change you suggested and I am now getting the following error
message:
[Microsoft Visual Basic]
Compile error:
User-defined type not defined

By the way following your suggestion, the code now is:
Sub DT()
'
' DT Macro
'
'
Dim Document As Word.Document
Dim Selection As Word.Selection

Set Document = Application.ActiveInspector.WordEditor
Set Selection = Document.ActiveWindow.Selection

Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
End Sub


Michael Bauer said:
Not tested but this might work. Add a reference to Word's library
(Tools/References) and insert this at the beginning of your code:

Dim Document as Word.Document
Dim Selection as Word.Selection

Set Document=Application.ActiveInspector.WordEditor
Set Selection=Document.ActiveWindow.Selection
Am Tue, 10 Jul 2007 18:44:01 -0700 schrieb Kevinsm:

Right, thanks Michael, it was a macro created in Word and then able to be
used in Outlook 2003 since Word was the message editor ... evidently no
longer the case.

The code is:
Sub DT()
'
' DT Macro
'
'
Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:=
_
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern,
_
InsertAsFullWidth:=False
End Sub

Thanks for your help!

:



Outlook never had a macro recorder, probably you're talking about Word.
What's the code?
Am Mon, 9 Jul 2007 22:48:00 -0700 schrieb Kevinsm:

In Outlook 2003 I was able to use a macro I had created in Word to
insert
the
day, date, and time at the beginning of a new email. Outlook 2007 has
no
"macro-record" function and my attempt to import a similar macro I
created
in
Word 2007 has failed ... when I run it, it results in an error message
and
I
have no clue how to debug. Any counsel?
 
S

Sue Mosher [MVP-Outlook]

PMJI, but Tools | References indeed is the correct command that you need to use in the Outlook VBA environment to add a reference to the Microsoft Word library.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Kevinsm said:
After brief research of 'Microsoft Word 2007 Object Library', I can't see
where or how to add a reference. Word 2007 doesn't have Tools/References in
the same way the earlier version did ... any help?

Michael Bauer said:
Did you add a ref to 'Microsoft Word x Object Library'?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 23:26:00 -0700 schrieb Kevinsm:
I made the change you suggested and I am now getting the following error
message:
[Microsoft Visual Basic]
Compile error:
User-defined type not defined

By the way following your suggestion, the code now is:
Sub DT()
'
' DT Macro
'
'
Dim Document As Word.Document
Dim Selection As Word.Selection

Set Document = Application.ActiveInspector.WordEditor
Set Selection = Document.ActiveWindow.Selection

Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
End Sub


:



Not tested but this might work. Add a reference to Word's library
(Tools/References) and insert this at the beginning of your code:

Dim Document as Word.Document
Dim Selection as Word.Selection

Set Document=Application.ActiveInspector.WordEditor
Set Selection=Document.ActiveWindow.Selection
Am Tue, 10 Jul 2007 18:44:01 -0700 schrieb Kevinsm:

Right, thanks Michael, it was a macro created in Word and then able to be
used in Outlook 2003 since Word was the message editor ... evidently no
longer the case.

The code is:
Sub DT()
'
' DT Macro
'
'
Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:=
_
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern,
_
InsertAsFullWidth:=False
End Sub

Thanks for your help!

:



Outlook never had a macro recorder, probably you're talking about Word.
What's the code?
Am Mon, 9 Jul 2007 22:48:00 -0700 schrieb Kevinsm:

In Outlook 2003 I was able to use a macro I had created in Word to
insert
the
day, date, and time at the beginning of a new email. Outlook 2007 has
no
"macro-record" function and my attempt to import a similar macro I
created
in
Word 2007 has failed ... when I run it, it results in an error message
and
I
have no clue how to debug. Any counsel?
 
K

Kevinsm

Thanks so much, Sue and Michael ... but it's probably obvious I'm a total
novice in these areas. Any chance of a quick step-by-step instruction as to
how to do what you're indicating?

Sue Mosher said:
PMJI, but Tools | References indeed is the correct command that you need to use in the Outlook VBA environment to add a reference to the Microsoft Word library.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Kevinsm said:
After brief research of 'Microsoft Word 2007 Object Library', I can't see
where or how to add a reference. Word 2007 doesn't have Tools/References in
the same way the earlier version did ... any help?

Michael Bauer said:
Did you add a ref to 'Microsoft Word x Object Library'?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 23:26:00 -0700 schrieb Kevinsm:

I made the change you suggested and I am now getting the following error
message:
[Microsoft Visual Basic]
Compile error:
User-defined type not defined

By the way following your suggestion, the code now is:
Sub DT()
'
' DT Macro
'
'
Dim Document As Word.Document
Dim Selection As Word.Selection

Set Document = Application.ActiveInspector.WordEditor
Set Selection = Document.ActiveWindow.Selection

Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:=
_
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern,
_
InsertAsFullWidth:=False
End Sub


:



Not tested but this might work. Add a reference to Word's library
(Tools/References) and insert this at the beginning of your code:

Dim Document as Word.Document
Dim Selection as Word.Selection

Set Document=Application.ActiveInspector.WordEditor
Set Selection=Document.ActiveWindow.Selection

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:

<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 18:44:01 -0700 schrieb Kevinsm:

Right, thanks Michael, it was a macro created in Word and then able to
be
used in Outlook 2003 since Word was the message editor ... evidently no
longer the case.

The code is:
Sub DT()
'
' DT Macro
'
'
Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:=
_
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm",
InsertAsField:=
_
False, DateLanguage:=wdEnglishUS,
CalendarType:=wdCalendarWestern,
_
InsertAsFullWidth:=False
End Sub

Thanks for your help!

:



Outlook never had a macro recorder, probably you're talking about Word.
What's the code?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:


<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Mon, 9 Jul 2007 22:48:00 -0700 schrieb Kevinsm:

In Outlook 2003 I was able to use a macro I had created in Word to
insert
the
day, date, and time at the beginning of a new email. Outlook 2007 has
no
"macro-record" function and my attempt to import a similar macro I
created
in
Word 2007 has failed ... when I run it, it results in an error message
and
I
have no clue how to debug. Any counsel?
 
S

Sue Mosher [MVP-Outlook]

Press Alt+F11 to open the VBA environment. Choose Tools | References. Scroll down till you find the Microsoft Word library. Check the box next to it. Close the references dialog. Add your code to a code module.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Kevinsm said:
Thanks so much, Sue and Michael ... but it's probably obvious I'm a total
novice in these areas. Any chance of a quick step-by-step instruction as to
how to do what you're indicating?

Sue Mosher said:
PMJI, but Tools | References indeed is the correct command that you need to use in the Outlook VBA environment to add a reference to the Microsoft Word library.


Kevinsm said:
After brief research of 'Microsoft Word 2007 Object Library', I can't see
where or how to add a reference. Word 2007 doesn't have Tools/References in
the same way the earlier version did ... any help?

:



Did you add a ref to 'Microsoft Word x Object Library'?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 23:26:00 -0700 schrieb Kevinsm:

I made the change you suggested and I am now getting the following error
message:
[Microsoft Visual Basic]
Compile error:
User-defined type not defined

By the way following your suggestion, the code now is:
Sub DT()
'
' DT Macro
'
'
Dim Document As Word.Document
Dim Selection As Word.Selection

Set Document = Application.ActiveInspector.WordEditor
Set Selection = Document.ActiveWindow.Selection

Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:=
_
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern,
_
InsertAsFullWidth:=False
End Sub


:



Not tested but this might work. Add a reference to Word's library
(Tools/References) and insert this at the beginning of your code:

Dim Document as Word.Document
Dim Selection as Word.Selection

Set Document=Application.ActiveInspector.WordEditor
Set Selection=Document.ActiveWindow.Selection

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:

<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 18:44:01 -0700 schrieb Kevinsm:

Right, thanks Michael, it was a macro created in Word and then able to
be
used in Outlook 2003 since Word was the message editor ... evidently no
longer the case.

The code is:
Sub DT()
'
' DT Macro
'
'
Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:=
_
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm",
InsertAsField:=
_
False, DateLanguage:=wdEnglishUS,
CalendarType:=wdCalendarWestern,
_
InsertAsFullWidth:=False
End Sub

Thanks for your help!

:



Outlook never had a macro recorder, probably you're talking about Word.
What's the code?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:


<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Mon, 9 Jul 2007 22:48:00 -0700 schrieb Kevinsm:

In Outlook 2003 I was able to use a macro I had created in Word to
insert
the
day, date, and time at the beginning of a new email. Outlook 2007 has
no
"macro-record" function and my attempt to import a similar macro I
created
in
Word 2007 has failed ... when I run it, it results in an error message
and
I
have no clue how to debug. Any counsel?
 
K

Kevinsm

Thanks, Sue. That seems to have done the trick ... in the sense that it's at
least now running. However, now I'm getting:
Run-time error '6158':
This object model command is not available in e-mail.

And it points to the code line:
Set Selection = Document.ActiveWindow.Selection
in the code Michael sent me to insert at the beginning of my original code.



Sue Mosher said:
Press Alt+F11 to open the VBA environment. Choose Tools | References. Scroll down till you find the Microsoft Word library. Check the box next to it. Close the references dialog. Add your code to a code module.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Kevinsm said:
Thanks so much, Sue and Michael ... but it's probably obvious I'm a total
novice in these areas. Any chance of a quick step-by-step instruction as to
how to do what you're indicating?

Sue Mosher said:
PMJI, but Tools | References indeed is the correct command that you need to use in the Outlook VBA environment to add a reference to the Microsoft Word library.


After brief research of 'Microsoft Word 2007 Object Library', I can't see
where or how to add a reference. Word 2007 doesn't have Tools/References in
the same way the earlier version did ... any help?

:



Did you add a ref to 'Microsoft Word x Object Library'?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 23:26:00 -0700 schrieb Kevinsm:

I made the change you suggested and I am now getting the following error
message:
[Microsoft Visual Basic]
Compile error:
User-defined type not defined

By the way following your suggestion, the code now is:
Sub DT()
'
' DT Macro
'
'
Dim Document As Word.Document
Dim Selection As Word.Selection

Set Document = Application.ActiveInspector.WordEditor
Set Selection = Document.ActiveWindow.Selection

Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm", InsertAsField:=
_
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern,
_
InsertAsFullWidth:=False
End Sub


:



Not tested but this might work. Add a reference to Word's library
(Tools/References) and insert this at the beginning of your code:

Dim Document as Word.Document
Dim Selection as Word.Selection

Set Document=Application.ActiveInspector.WordEditor
Set Selection=Document.ActiveWindow.Selection

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:

<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 10 Jul 2007 18:44:01 -0700 schrieb Kevinsm:

Right, thanks Michael, it was a macro created in Word and then able to
be
used in Outlook 2003 since Word was the message editor ... evidently no
longer the case.

The code is:
Sub DT()
'
' DT Macro
'
'
Selection.InsertDateTime DateTimeFormat:="dddd, dd MMMM, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:=
_
wdCalendarWestern, InsertAsFullWidth:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=5
Selection.TypeBackspace
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" / "
Selection.InsertDateTime DateTimeFormat:="h:mm am/pm",
InsertAsField:=
_
False, DateLanguage:=wdEnglishUS,
CalendarType:=wdCalendarWestern,
_
InsertAsFullWidth:=False
End Sub

Thanks for your help!

:



Outlook never had a macro recorder, probably you're talking about Word.
What's the code?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:


<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Mon, 9 Jul 2007 22:48:00 -0700 schrieb Kevinsm:

In Outlook 2003 I was able to use a macro I had created in Word to
insert
the
day, date, and time at the beginning of a new email. Outlook 2007 has
no
"macro-record" function and my attempt to import a similar macro I
created
in
Word 2007 has failed ... when I run it, it results in an error message
and
I
have no clue how to debug. Any counsel?
 
S

Sue Mosher [MVP-Outlook]

Do you have an individual Outlook message open in its own window? Also, you might try the syntax I've posted at http://turtleflock-ol2007.spaces.live.com/blog/cns!C1013F1F9A99E3D8!579.entry useful.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Kevinsm said:
Thanks, Sue. That seems to have done the trick ... in the sense that it's at
least now running. However, now I'm getting:
Run-time error '6158':
This object model command is not available in e-mail.

And it points to the code line:
Set Selection = Document.ActiveWindow.Selection
in the code Michael sent me to insert at the beginning of my original code.
Am Tue, 10 Jul 2007 23:26:00 -0700 schrieb Kevinsm:
 
K

Kevinsm

Success! Your syntax did it, Sue. Thanks so much ... a great learning
experience for me!
 

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