Consulting

Results 1 to 4 of 4

Thread: Simple macro in Outlook to remove spacing: Object required error message

  1. #1
    VBAX Newbie
    Joined
    Jan 2023
    Posts
    2
    Location

    Simple macro in Outlook to remove spacing: Object required error message

    I created a macro to remove spacing successfully in Word and it looks like this:
    Selection.Style = ActiveDocument.Styles("No Spacing")
    -- with the appropriate Sub and End Sub.

    When I created a macro in Outlook and typed in the same content, it did not work.
    Error message was:
    Run-time error '424':
    Object required

    What did I do wrong?

    I am obviously a VBA newbie. I want to select text in an email and use a keyboard macro to remove spacing -- without having to right-click to access paragraph settings or open the email and go to Format Text.

    Thank you.

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    331
    Location
    Why would you expect Word code to work in Outlook?

    Emails are not document files.

    You want to edit an incoming email?
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    VBAX Newbie
    Joined
    Jan 2023
    Posts
    2
    Location
    Hi June7,
    I was hoping that formatting code that works in Word would work in Outlook. I thought the underlying editor in Outlook is the same 'engine' as in Word. Where can I go to learn the code(s) specific to Outlook?
    Thank you very much!

  4. #4
    No that is not right way to use same code on word and outlook. Try this code:

    <pre>Sub FixParagraphSpacing()    
    Dim objOL As Application
    Dim objDoc As Object
    Dim objSel As Object
    Set objOL = Application
    Set objDoc = objOL.ActiveInspector.WordEditor
    Set objSel = objDoc.Windows(1).Selection
    objSel.ParagraphFormat.SpaceBefore = 0
    objSel.ParagraphFormat.SpaceBeforeAuto = False
    objSel.ParagraphFormat.SpaceAfter = 0
    objSel.ParagraphFormat.SpaceAfterAuto = False
    Set objOL = Nothing
    Set objDoc = Nothing
    Set objSel = Nothing End Sub </pre>
    may be it is helpful for you.
    Last edited by Aussiebear; 05-23-2023 at 12:49 AM. Reason: Corrected the Code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •