focusers
asked on
Create or import macros into Outlook 2007
I used the learn macro function in MS Word to create two macros: I assign a key or ribbon icon to "double indent" which means that after I highlight a paragraph, the macro causes the text to be single space, and indented 2" on both the left and right borders. I use this to insert quotes into my papers. I have a second macro that returns to normal by making the spacing double, and restoring the paragraph to 0" indent on the left and right.
I want to import these two macros into Outlook 2007, or alternatively crerate them in Outlook 2007. However, I have not been able to use or understand the macro editior in Outlook or to create any macro that works.
I want to import these two macros into Outlook 2007, or alternatively crerate them in Outlook 2007. However, I have not been able to use or understand the macro editior in Outlook or to create any macro that works.
ASKER
Blue:
The code for the two macros I use in Word 2007 (that I want to use in Outlook 2007) is as follows (one is called "dbindt" --for double indenting a paragraph I had highlighted-- and the other is called "Normal" --for returning the page to its original status):
Sub dbindt()
'
' dbindt Macro
'
'
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(1.5)
.RightIndent = InchesToPoints(1.5)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(1.15)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineInd ent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
Sub normal()
'
' normal Macro
'
'
With Selection.Font
.Name = "Calibri"
.Size = 12
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(1.15)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineInd ent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
My goal is to have these work in Outlook 2007 as imported macros or re-written for Outlook 2007.
Thanks.
(Should I raise the difficulty point level of this question?)
The code for the two macros I use in Word 2007 (that I want to use in Outlook 2007) is as follows (one is called "dbindt" --for double indenting a paragraph I had highlighted-- and the other is called "Normal" --for returning the page to its original status):
Sub dbindt()
'
' dbindt Macro
'
'
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(1.5)
.RightIndent = InchesToPoints(1.5)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(1.15)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineInd
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
Sub normal()
'
' normal Macro
'
'
With Selection.Font
.Name = "Calibri"
.Size = 12
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(1.15)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineInd
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
My goal is to have these work in Outlook 2007 as imported macros or re-written for Outlook 2007.
Thanks.
(Should I raise the difficulty point level of this question?)
Here's they are revised to work from Outlook. Follow these instructions to use them.
1. Start Outlook.
2. Click Tools > Macro > Visual Basic Editor.
3. If not already expanded, expand Modules and click on Module1. If Module1 doesn't exist, then create it.
4. Copy the code below and paste it into the right-hand pane of the VB Editor.
5. Edit the code as needed. I placed comments where things must/should be edited.
6. Click Tools > References
7. Scroll down through the list of references until you find Microsoft Word 12.0 Object model. Check the box next to it and click OK.
8. Click the diskette icon on the toolbar to save the changes.
9. Close the VB Editor.
Open a message and selected some text. Run one of the macros.
The point value of the question is up to you.
1. Start Outlook.
2. Click Tools > Macro > Visual Basic Editor.
3. If not already expanded, expand Modules and click on Module1. If Module1 doesn't exist, then create it.
4. Copy the code below and paste it into the right-hand pane of the VB Editor.
5. Edit the code as needed. I placed comments where things must/should be edited.
6. Click Tools > References
7. Scroll down through the list of references until you find Microsoft Word 12.0 Object model. Check the box next to it and click OK.
8. Click the diskette icon on the toolbar to save the changes.
9. Close the VB Editor.
Open a message and selected some text. Run one of the macros.
The point value of the question is up to you.
Sub dbindt()
Dim olkMsg As Outlook.MailItem, _
olkDoc As Object, _
wrdSelection As Object
Set olkMsg = Application.ActiveInspector.CurrentItem
Set olkDoc = Application.ActiveInspector.WordEditor
Set wrdSelection = olkDoc.Application.Selection
With wrdSelection.ParagraphFormat
.LeftIndent = olkDoc.Application.InchesToPoints(1.5)
.RightIndent = olkDoc.Application.InchesToPoints(1.5)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = olkDoc.Application.LinesToPoints(1.15)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = olkDoc.Application.InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
Sub normal()
Dim olkMsg As Outlook.MailItem, _
olkDoc As Object, _
wrdSelection As Object
Set olkMsg = Application.ActiveInspector.CurrentItem
Set olkDoc = Application.ActiveInspector.WordEditor
Set wrdSelection = olkDoc.Application.Selection
With wrdSelection.Font
.Name = "Calibri"
.Size = 12
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.Strikethrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.Smallcaps = False
.Allcaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
With wrdSelection.ParagraphFormat
.LeftIndent = olkDoc.Application.InchesToPoints(0)
.RightIndent = olkDoc.Application.InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = olkDoc.Application.LinesToPoints(1.15)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = olkDoc.Application.InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
ASKER
Blue,
Thank you for the code, I really do appreciate it, and I am sorry I did not make this a 500 point question. If I can change it, tell me how, and I will.
We are almost there. There are two problems: On each of the macros, I get the following error message-
Microsoft Visual Basic
-------------------------- -
Runtime error '5148';
The number must be between 1 and 1o
[END] [DEBUG] [HELP]
Then the VB editior opens automatically . When I click "END" and the macro works.
How do I get rid of this error.
The second issue is that in the double indent macro (dbindt) I need the line spacing to be single space.
Thanks again.
Thank you for the code, I really do appreciate it, and I am sorry I did not make this a 500 point question. If I can change it, tell me how, and I will.
We are almost there. There are two problems: On each of the macros, I get the following error message-
Microsoft Visual Basic
--------------------------
Runtime error '5148';
The number must be between 1 and 1o
[END] [DEBUG] [HELP]
Then the VB editior opens automatically . When I click "END" and the macro works.
How do I get rid of this error.
The second issue is that in the double indent macro (dbindt) I need the line spacing to be single space.
Thanks again.
What line are you taken to in the debugger?
ASKER
In the "dbindt" macro, the line says".OutlineLevel = wdOutlineLevelBodyText". (See, below)
Sub dbleindt()
Dim olkMsg As Outlook.MailItem, _
olkDoc As Object, _
wrdSelection As Object
Set olkMsg = Application.ActiveInspecto r.CurrentI tem
Set olkDoc = Application.ActiveInspecto r.WordEdit or
Set wrdSelection = olkDoc.Application.Selecti on
With wrdSelection.ParagraphForm at
.LeftIndent = olkDoc.Application.InchesT oPoints(1. 5)
.RightIndent = olkDoc.Application.InchesT oPoints(1. 5)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = olkDoc.Application.LinesTo Points(1.1 5)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = olkDoc.Application.InchesT oPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineInd ent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
-------------------------- ---------- --------
In the "Normal" macro, the lnie says:. "OutlineLevel = wdOutlineLevelBodyText" as shown below;
Sub normal()
Dim olkMsg As Outlook.MailItem, _
olkDoc As Object, _
wrdSelection As Object
Set olkMsg = Application.ActiveInspecto r.CurrentI tem
Set olkDoc = Application.ActiveInspecto r.WordEdit or
Set wrdSelection = olkDoc.Application.Selecti on
With wrdSelection.Font
.Name = "Calibri"
.Size = 12
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.Strikethrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.Smallcaps = False
.Allcaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
With wrdSelection.ParagraphForm at
.LeftIndent = olkDoc.Application.InchesT oPoints(0)
.RightIndent = olkDoc.Application.InchesT oPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = olkDoc.Application.LinesTo Points(1.1 5)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = olkDoc.Application.InchesT oPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineInd ent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
I hope that I gave you what you need.
thaks.
Sub dbleindt()
Dim olkMsg As Outlook.MailItem, _
olkDoc As Object, _
wrdSelection As Object
Set olkMsg = Application.ActiveInspecto
Set olkDoc = Application.ActiveInspecto
Set wrdSelection = olkDoc.Application.Selecti
With wrdSelection.ParagraphForm
.LeftIndent = olkDoc.Application.InchesT
.RightIndent = olkDoc.Application.InchesT
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = olkDoc.Application.LinesTo
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = olkDoc.Application.InchesT
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineInd
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
--------------------------
In the "Normal" macro, the lnie says:. "OutlineLevel = wdOutlineLevelBodyText" as shown below;
Sub normal()
Dim olkMsg As Outlook.MailItem, _
olkDoc As Object, _
wrdSelection As Object
Set olkMsg = Application.ActiveInspecto
Set olkDoc = Application.ActiveInspecto
Set wrdSelection = olkDoc.Application.Selecti
With wrdSelection.Font
.Name = "Calibri"
.Size = 12
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.Strikethrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.Smallcaps = False
.Allcaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
With wrdSelection.ParagraphForm
.LeftIndent = olkDoc.Application.InchesT
.RightIndent = olkDoc.Application.InchesT
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = olkDoc.Application.LinesTo
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = olkDoc.Application.InchesT
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineInd
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
I hope that I gave you what you need.
thaks.
I just ran both macros and did not get any errors. Do you have any other code in Outlook? wdOutlineLevelBodyText is a constant with a value of 10. The only reason I can think of that you'd get an error when I don't is if there is other code in Outlook that's changing the declaration of that constant name.
ASKER
Blue,
In Macros, I ahve just the two you wrote.
Where can I look to see if there is the other code you suspect?
is there a workaround/ I mean, is there a substitute for wdOutlineLevelBodyText that m Outlook might accept?
Also, how do I get dbindt to go to single line space instead of double line space?
In Macros, I ahve just the two you wrote.
Where can I look to see if there is the other code you suspect?
is there a workaround/ I mean, is there a substitute for wdOutlineLevelBodyText that m Outlook might accept?
Also, how do I get dbindt to go to single line space instead of double line space?
ASKER
Blue:
I deleted the two offending items of code--and SUCCESS!
Now I need to impose on you to change the code in dbindt so it does not double space the text. Since I use this to quote paragraphs, I need the quote in single space.
So far, so good.
thanks for sticking with this.
I deleted the two offending items of code--and SUCCESS!
Now I need to impose on you to change the code in dbindt so it does not double space the text. Since I use this to quote paragraphs, I need the quote in single space.
So far, so good.
thanks for sticking with this.
ASKER
I figured out how to rauise the points.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think there must be another setting on your system that's causing the double spacing. It doesn't double-space on my system. Also, curious what you deleted that got it working.
ASKER
Great Air-Traffic-Control type of help. A difficult problem was solved.
ASKER
I deleted the exact lines I quoted to you above (which were highlighted in the debug screen.
As for the double spacing, the Word Macro actually does single spacing (even when the quoted paragraph is double spaced).
As for the double spacing, the Word Macro actually does single spacing (even when the quoted paragraph is double spaced).
Macros and how they work is completely different in Outlook than in other Office products, especially Word and Excel. Outlook does not have the ability to record macros like those two products do. Outlook macros have to be written from scratch using VBA. I'd have to see one of these Word macros to be sure, but I'm inclined to think that it probably won't work in Outlook at all. If you want to post one of them here, then I'll be glad to have a look and let you know. Since Outlook 2007 uses Word for it's editor, there might be a way to call the Word macro from Outlook, but I'm not certain of that.
The macro editor, really VBA editor, in Outlook is a combination code editor and debugger. Writing code is simple enough if you are comfortable with VBA (Microsoft Visual Basic for Applications) and have some knowledge of Outlook's object model.