Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-10-2014, 08:43 AM
Ulodesk Ulodesk is offline Macro problem Windows 7 64bit Macro problem Office 2013
Word 2013 Expert Cert
Macro problem
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Macro problem

I have tried to follow the directions for using Outlook's (2010) VBA, provided here http://www.slipstick.com/developer/h...ks-vba-editor/, but am running into problems.

This simple macro, the same as Word's, placed in my QAT, is not working.

Code:
Sub PasteUnformatted()
'
' PasteUnformatted Macro
'
'
    Selection.PasteSpecial Link:=False, DataType:=wdPasteText
End Sub
I get a debug pop-up and find the entire macro highlighted.

In Word, I have set [Alt+Ctrl+V] to run the above macro, and I'd like to be able to do that in Outlook messages. I can't find a way to create keyboard shortcuts, except for forum posts on Autohotkey, that appear to involve potential issues and registry editing.



Also, if I can get copy and paste formatting (Ctrl+Shift+C and Ctrl+Shift+V) onto the QAT, the Alt+number shortcuts would be fine, as a substitute for these Word shortcuts.

Help would be appreciated.
Reply With Quote
  #2  
Old 08-10-2014, 12:01 PM
niton niton is offline Macro problem Windows 7 64bit Macro problem Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default

The code in Outlook looks more like this. Untested.

Code:
Option Explicit

Public Sub PasteUnformatted()

Dim oDoc As Object
Dim itm As Object
Dim objSel As Word.Selection

On error resume next
Set itm = Application.ActiveInspector.CurrentItem
on error goto 0

if itm is nothing then
    msgbox "Something wrong with current item"
    exit sub
end if

If itm.GetInspector.EditorType = olEditorWord Then
    Set oDoc = itm.GetInspector.WordEditor
    Set objSel = objDoc.Windows(1).Selection
    objSel.PasteSpecial Link:=False, DataType:=wdPasteText
End If

End Sub
No shortcuts except Alt+number shortcuts.
Reply With Quote
  #3  
Old 08-11-2014, 03:55 PM
Ulodesk Ulodesk is offline Macro problem Windows 7 64bit Macro problem Office 2013
Word 2013 Expert Cert
Macro problem
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default code problem

Thank you for providing the macro. I tried it, but it returned this line

Code:
Set objSel = objDoc.Windows(1).Selection
with "obj.Doc" highlighted, and pop-up saying variable not defined.

Any ideas?
Reply With Quote
  #4  
Old 08-12-2014, 06:29 AM
niton niton is offline Macro problem Windows 7 64bit Macro problem Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default

I did add Dim objSel As Word.Selection. But this may still not be enough.

This link provides details. http://www.slipstick.com/developer/w...outlook-email/

Code:
Public Sub FormatSelectedText()
    Dim objItem As Object
    Dim objInsp As Outlook.Inspector
     
    ' Add reference to Word library
    ' in VBA Editor, Tools, References
    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    
   'On Error Resume Next ' <--- Do not use this unless you have a specific purpose
    
'Reference the current Outlook item 
    Set objItem = Application.ActiveInspector.currentItem
    If Not objItem Is Nothing Then
        If objItem.Class = olMail Then
            Set objInsp = objItem.GetInspector
            If objInsp.EditorType = olEditorWord Then
                Set objDoc = objInsp.WordEditor
                Set objWord = objDoc.Application
                Set objSel = objWord.Selection
 
 
' replace the With block with your code
       With objSel
       ' Formatting code goes here
            .Font.Color = wdColorBlue
            .Font.Size = 18
            .Font.Bold = True
            .Font.Italic = True
            .Font.Name = "Arial"
       End With
 
            End If
        End If
    End If
     
    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing
End Sub
Reply With Quote
  #5  
Old 08-12-2014, 08:14 AM
Ulodesk Ulodesk is offline Macro problem Windows 7 64bit Macro problem Office 2013
Word 2013 Expert Cert
Macro problem
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Code

Thank you again; I do appreciate your time and talent. I am entirely novice in VBA; I had no idea this would be so involved, since it is so easy in Word.

It appears to me from the new code you have provided, that instead of pasting unformatted to paste copied text to adopt the style of my recipient paragraph, I am applying a specific formatting that is inflexible. Is this a correct reading? If so, and since I can paste unformatted via the Ribbon, as in Word (in Outlook: Format text/Paste/Paste special/Unformatted text), is there not a way to trigger this same command in a macro?
Reply With Quote
  #6  
Old 08-12-2014, 11:14 PM
gmayor's Avatar
gmayor gmayor is offline Macro problem Windows 7 64bit Macro problem Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Returning to the original premise which was, I believe, to paste unformatted text into the body of an e-mail message, the code you need for that is as follows. Note that it only works if the cursor is in the body of the message.

Code:
Sub PasteUnfText()
On Error GoTo ErrHandler
If TypeName(ActiveWindow) = "Inspector" Then
    If ActiveInspector.IsWordMail And ActiveInspector.EditorType = olEditorWord Then
        ActiveInspector.WordEditor.Application.Selection.PasteSpecial DataType:=2        ' wdPasteText
    End If
End If
Exit Sub
ErrHandler:
Beep
End Sub
Once you have determined that the ActiveInspector is the Word editor, then the process is very similar to using VBA in Word.

Graham Mayor MS MVP(Word)
www.gmayor.com
Reply With Quote
  #7  
Old 08-13-2014, 04:50 AM
Ulodesk Ulodesk is offline Macro problem Windows 7 64bit Macro problem Office 2013
Word 2013 Expert Cert
Macro problem
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Paste unf

Bravo! Thank you very much.
Reply With Quote
  #8  
Old 08-26-2014, 11:18 AM
niton niton is offline Macro problem Windows 7 64bit Macro problem Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default

Where you see

Code:
 
' replace the With block with your code
       With objSel
       ' Formatting code goes here
            .Font.Color = wdColorBlue
            .Font.Size = 18
            .Font.Bold = True
            .Font.Italic = True
            .Font.Name = "Arial"
       End With
use

Code:
 
objSel.PasteSpecial Link:=False, DataType:=wdPasteText

Code:
 
Public Sub PasteUnformatted_OutlookVersion()
    Dim objItem As Object
    Dim objInsp As Outlook.Inspector
 
    ' Add reference to Word library
    ' in VBA Editor, Tools, References
    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
 
   'On Error Resume Next ' <--- Do not use this unless you have a specific purpose
 
'Reference the current Outlook item
    Set objItem = Application.ActiveInspector.CurrentItem
    If Not objItem Is Nothing Then
        If objItem.Class = olMail Then
            Set objInsp = objItem.GetInspector
            If objInsp.EditorType = olEditorWord Then
                Set objDoc = objInsp.WordEditor
                Set objWord = objDoc.Application
                Set objSel = objWord.Selection
 
                objSel.PasteSpecial Link:=False, DataType:=wdPasteText
 
            End If
        End If
    End If
 
    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
EXCEL macro problem please help! ryguy551 Excel Programming 2 05-22-2014 03:58 PM
Problem with macro MS baby Excel Programming 4 03-31-2014 02:47 PM
Macro problem Problem with macro tmill29 Excel Programming 1 06-08-2013 09:59 AM
Macro problem Moving data macro problem MattMurdock Excel Programming 1 07-20-2012 04:49 AM
Macro problem Another simple macro problem Ulodesk Word VBA 1 06-08-2012 06:24 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:21 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft