Paste from Windows Clipboard then change font without losing formatting

Status
Not open for further replies.
Outlook version
Email Account
Exchange Server
I need a little help on a macro that will help simplify copying and pasting from a Console terminal window into an email and be able to keep the formatting, yet change the font. What I need to do to make it look right is paste it into the email and then change all the text to "Courier New" from "Calibri" and the spacing and everything looks very close to what is in the terminal window. I can do everything I need to do, but when I change the text using the HTMLBody and font tags, I loose all the spacing and formating of my text string. I guess it's easy enough to just paste the stuff into the email and then highlight it and change the font, but I'd really just like to do it in VBA just because it is stumping me.

Sub sendmyemail()

Dim OutMail As Object
Dim strbody As String
Dim DataObj As MSForms.DataObject
Set DataObj = New MSForms.DataObject
DataObj.GetFromClipboard
strpaste = DataObj.GetText(1)

Set OutMail = Outlook.CreateItem(olMailItem)


With OutMail
.Display
.To = "FOChangelist"
.Subject = "FO Change"
.Body = strpaste

'The above works and I don't lose my spacing and line format, but it is a little jumbled. I paste it and change 'the font and the "jumbledness" goes away and the spacing looks very close to what I need.

'or use the :

.HTMLBody = "<font face=Courier New>" & strpaste & "</font>"

'The above loses all the space and line formatting.


'Example of comments to paste into the body of the email. or something very close
'or use the HTML Body
'1. 01/31/17 01 SERVICE: CONSULT WITH ENGINEERING ON THE BLOWER SPRINGS FOR
' GWM AC-4. THE SPRINGS WERE CHANGED LAST MINUTE AND APPROVED BY
' ENGINEERING.
'2. 01/26/17 01 Per customer AC-6 will ship on 03/15 and be onsite 03/23. Th
' S S e ship/onsite schedule for remaining units stay the same as
' below.
'3. 01/13/17 01 Provide one "empty conduit from control panel to the supply
' NSZ , return duct sections and to NEMA boxes, on units that
' require a NEMA box, for field installation & wiring of
' smoke detectors.


.Display
End With



Set OutMail = Nothing
Set DataObj = Nothing
End Sub
 
I'm pretty sure this will work with Outlook 2007 -

See Create Task or Appointment and Insert Selected Text for a method that uses word. Since you have the text copied, you will ship the section that copies - the import part is the paste:
objSel.PasteAndFormat (wdFormatOriginalFormatting)
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J PSA: How to create custom keyboard shortcut for "Paste Unformatted Text" in Outlook on Windows Outlook VBA and Custom Forms 1
P Outlook 2016 Change Paste Special Default Format Using Outlook 8
P Can't paste an image into a task Using Outlook 3
P Add Paste Unformatted to QAT Using Outlook 1
B Paste formatted text (bold, underlined and in quotes) Outlook VBA and Custom Forms 1
J VBA Outlook : Subject line : Cut and Paste name to heading , number to very end of the body of Email Outlook VBA and Custom Forms 1
O Macro - paste as plain text Outlook VBA and Custom Forms 2
D Paste Excel table into Outlook message Outlook VBA and Custom Forms 6
O How to paste website content using a specific font and removing URLs Using Outlook 2
D Outlook macro with today's date in subject and paste clipboard in body Outlook VBA and Custom Forms 1
N Paste content to Excel when .txt file (attachment) is opened Outlook VBA and Custom Forms 1
Stilgar Relsik Create a rule to copy text from an email and paste it in the subject line. Using Outlook 1
H Macro to Copy Specific content from Mail Body and Paste to Excel Outlook VBA and Custom Forms 4
Diane Poremsky Paste clipboard contents using VBA Using Outlook 0
A Outlook: copy & paste Outlook VBA and Custom Forms 9
V Copy and paste body and subject and send multiple emails Outlook VBA and Custom Forms 3
G outlook 13 copy & paste without losing formatting Using Outlook 1
C Copy Cell value from Excel and paste into current email Outlook VBA and Custom Forms 10
R Copy/paste mailing address Outlook 2013 Using Outlook 6
D Open attached CSV, copy newdata and paste it to database CSV Outlook VBA and Custom Forms 2
O Copy email content and paste into new Word Document using a different font Using Outlook 1
makinmyway Research Pane in Emails Turns on and Cut Paste Keys then Stop Working Using Outlook 5
L Outlook 2007 Delete and Paste Between Fields Using Outlook 25
L "sometimes" cant send mail, we have to copy and paste the message and resend? Using Outlook 2
I Clipboard paste in macro Using Outlook 14
F Cut and Paste Addresses from Excel Suddenly Limited Using Outlook 4
N Cut and Paste Taking 25 seconds Using Outlook 0
R how to copy a list of email contacts and paste them only as names (not names + email address) Using Outlook 12
G Outlook 2007 Macro: Paste - Paste Special - Unformatted Text Outlook VBA and Custom Forms 9
K Copy Entire Email Content - Paste into new Task Outlook VBA and Custom Forms 2
K How to copy Contact Item to Clipboard and Paste as "VCF Link? Outlook VBA and Custom Forms 4
Z unable to paste screenshot into custom form Outlook VBA and Custom Forms 2
S Using copy paste to grab email addresses from the TO: address fiel Using Outlook 14
S Related messages show in main Outlook window vice new Advanced Find windows Using Outlook 1
G Outlook 365 My iCloud Outlook doesn’t work after reinstalling Microsoft365 on Windows 10 PC – now I get error message on contacts and calendar Using Outlook 1
D Lifelong Windows user - new to Mac - Help!!! Using Outlook 3
J Unable to delete folders in Outlook 2019 / Windows Using Outlook 0
Z New minimum Outlook for Windows version requirements for Microsoft 365/Exchange Online Using Outlook.com accounts in Outlook 27
T How to configure Outlook for two users on a single Windows account Using Outlook 3
R Outlook 2021 Having problem setting up outlook 2021 with windows 11. I have 3 gmail accounts and I want the 3 gmail, emails to merge into the same outlook input. Using Outlook.com accounts in Outlook 0
Commodore Safe way to add or update holidays; Windows Notifications issue Using Outlook 8
C Why does Outlook (desktop) 365 for Windows keep making me input my passwords? Using Outlook 12
V Outlook 2021 Outlook-2021 (64-bit) and iCloud-for-Windows v13.0 - It Works Good. Using Outlook 12
V Outlook 2016 iCloud for Windows - Why no working Calendars and Tasks ? Using Outlook 1
V Outlook 2003 and Windows 11 Using Outlook 4
G VBA to save selected Outlook msg with new name in selected network Windows folder Outlook VBA and Custom Forms 1
T Why is every new email pinned (to keep it on top)? Windows 10 Using Outlook 6
B Emails get stuck in Outbox of Gmail IMAP in Outlook for Windows Using Outlook 0
V Outlook 2016 Does Outlook-2016 (64 bit) work with iCloud for Windows ? Using Outlook 5
V Outlook 2016 Outlook-2016 and iCloud for Windows - Problems Using Outlook 11

Similar threads

Back
Top