HTA creating Outlook MeetingItem - need formatted body text

Status
Not open for further replies.

PGilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Hi All, I'm new here but have already found several solutions to my existing problems. Thanks!

One problem remains vexing, though. I am using an HTA to create an Outlook MeetingItem (appointment) from a "calendar-like" formatted text and attachments copied to the Clipboard, but I have not been able to figure out how to copy the Clipboard text to the Body in the Meeting as formatted text. Further, the attachments don't come over (but do when I do this manually by pasting the Clipboard to the body as formatted text).

Here is the sub at issue:

Code:
Sub outl(x)
    Dim olApp : Set olApp = CreateObject("Outlook.Application")  '  this gets/creates the outlook instance
    Dim cont : cont = document.parentwindow.clipboardData.GetData("text")  '  this pulls in the clipboard
    if IsNull(instr(cont,"Subject: ")) then msgbox "You need to copy a mtg text first" : exit sub  '  check to make sure I some clipboard text
    if instr(cont,"Subject: ") < 1 then msgbox "You need to copy a mtg text first" : exit sub  '  now check to see if clipboard contains "calendar-like" text
    Dim olCal : Set olCal = olApp.CreateItem(1)  '  1 is for creating an olAppointmentItem
    olCal.MeetingStatus = 1  '  1 is to make it an olMeeting
    olCal.Recipients.Add("myrecipient@blahblah.com")  '  populate recipients
    olCal.Subject = "bn " & mid(cont, instr(cont,"Subject: ")+9, instr(cont,"When: ")-instr(cont,"Subject: ")-11)  '  populate subject
    olCal.Location = mid(cont, instr(cont,"Where: ")+7)  '  populate location
    olCal.Body = cont  '  This gives me unformatted text and no attachments.  I want it formatted (but .HTMLBody is not supported by this item type).
    Dim conts  '  a bunch of fancy text manipulations to find start and end times (there may be a better way, but it works)
    conts = mid(cont, instr(cont,"When: ")+6, instr(mid(cont, instr(cont,"When: ")+6),"-")-1)
    conts = mid(conts, instr(conts, "day,")+5)
    olCal.Start = cdate(conts)  '  after all that, here is the start date and time
    conts = mid(cont, instr(cont,"When: ")+6, instr(mid(cont, instr(cont,"When: ")+6),"GMT")-2)
    conts = mid(conts, instr(conts, "day,")+5)
    conts = left(conts, instr(conts, ", ")+6) & mid(conts, instr(conts, "-")+1)
    olCal.End = cdate(conts)  '  and here is the end date and time
    olCal.Display  '  now bring up the MeetingRequest item
    Set cont = Nothing
    Set conts = Nothing
    Set olApp = Nothing 
 
End Sub

Any suggestions, clues? TIA

PGilm
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Does it work if you use the forms object to paste? (it doesn't here, but I have a lot of your code commented out)

formatted text in the body of outlook items is tricky because it doesn't use html format, only rtf, so you can't use htmlbody like you would for email. Redemption can do it, but it's funky and the results aren't always what you would expect.

AFAIK, you can't use the 'keep source formatting' command in VBA.

I don't know if you can use this method - VBOffice - Samples - it may only work with mail.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Yes, you can use the keep source command - you do need to set word as a reference in tools > references to use it.

This code works - I was running into problems because I wasn't displaying the olcal after it was created. Once I moved the display line, it was perfect.

This assumes I have something on the clipboard before I run it.

Code:
Sub outl()
   On Error Resume Next
       Dim olCal: Set olCal = Application.CreateItem(1)
       olCal.Subject = "bn " & Now
       olCal.Location = "here" 
 
olCal.Display
   
 
Dim objItem As Object 
 
Dim objInsp As Outlook.Inspector 
 
Dim objWord As Word.Application 
 
Dim objDoc As Word.Document 
 
Dim objSel As Word.Selection 
 
Set objItem = olCal ' Application.ActiveInspector.currentItem 
 
Set objInsp = objItem.GetInspector 
 
Set objDoc = objInsp.WordEditor 
 
Set objWord = objDoc.Application 
 
Set objSel = objWord.Selection 
 
objSel.PasteAndFormat (Word.WdRecoveryType.wdFormatOriginalFormatting)
    Set cont = Nothing
    Set conts = Nothing
    Set olApp = Nothing 
 
End Sub
 

PGilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
This looks good -- I have been playing around with the Inspector, but no luck so far. I will report back once I've tried again using your model (probably not till later).

One problem, though, with VBScript in an HTA, is that there is no early binding that I know of. So I can't "reference" anything that way. So, on the Dims, do I just leave out the "as somethings" and proceed, or do I need to also CreateObjects (such as the Outlook.Inspector and/or the Word.Application)?

In the meantime, I have this kludge, using "SendKeys" (I know, I don't like it either) but don't know the keyboard shortcut for jumping to the body of the Meeting Request (I have the 8 tabs to do it). Do you know of one?

Code:
    Dim S : Set S = CreateObject("WScript.Shell")
    S.AppActivate "bn "
    Delay 2  '  Delay is a sub I wrote for pausing, in this case, around 2 seconds
    S.SendKeys "{tab 8}^v^{Home}"
    Set S = Nothing

Many Thanks!!!

-PGilm
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Arrr... forgot about the binding. It may work to leave out the 'as something' part of the dim, but it's usually better to create the objects and properly dim them. In the case of word, I'm pretty sure you will need to use createobject.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Fozzie Bear Outlook 2016 Creating a shared local Contacts folder Using Outlook 2
R Creating a user defined function Outlook VBA and Custom Forms 3
M Creating an RSS Feed **FROM** Outlook 2013 Calendar. Using Outlook 5
O How to prevent CC from showing when creating a new mail? Using Outlook 1
N Creating a button or link to a form in the Organizational Forms Library Outlook VBA and Custom Forms 3
B Creating an email with the list of tasks Outlook VBA and Custom Forms 0
L Creating drafts when I thought I was sending Using Outlook 1
R Would creating a new profile cause Outlook to download all the old mails from the server? Using Outlook 1
A Creating Progress Bar or Status Bar Update Outlook VBA and Custom Forms 0
T Outlook creating a folder named: "Unwanted" Using Outlook 3
M Outlook 2007 Contacts Glitch: Creating a new email Using Outlook 1
Liza Creating a rule in outlook to filter messages Using Outlook 0
A Are categories still recommended for creating local distribution lists? Using Outlook 3
S Creating Email - Selecting Pre-Defined Text Using Outlook 2
D Creating an outlook session from Access vba but run silently. With A specific profile Outlook VBA and Custom Forms 1
M Creating Outlook Appointments from Excel Cells Outlook VBA and Custom Forms 1
N Creating New Profile Using Outlook 0
Y Creating custom appointment request form with multiple mail recipients Outlook VBA and Custom Forms 5
M creating email from contact file = 3 emails in To field Using Outlook 3
P Recover / Extract Rules from standalone PST file creating RWZ file Using Outlook 2
A Creating an outlook rule to forward an email with a specific message Using Outlook 1
I Creating meeting invite with disabled tentative button Outlook VBA and Custom Forms 5
E Creating email templates for organizational use Using Outlook 0
N Creating or changing the main new mail message template in Outlook 2010 Using Outlook 2
D Creating custom view with VBA Outlook VBA and Custom Forms 2
J Outlook creating unwanted rule on its own Using Outlook 1
R Creating a Room Mailbox with Exchange Online Outlook VBA and Custom Forms 0
A Creating a rule on “Deleted items” folder Using Outlook 1
CMG73 Creating templates with predefined subject and CC Using Outlook 1
G Creating Contact Sub Folders Using Outlook 2
Rupert Dragwater creating gmail account in Outlook 2013 Using Outlook 7
nathandavies Creating a Select Case for a directory of folders Outlook VBA and Custom Forms 1
2 creating custom stationery Using Outlook 2
A Help creating macro for conditional formatting settings Using Outlook 8
Fozzie Bear Creating Custom Meeting Form Outlook VBA and Custom Forms 6
U Creating a (This computer only) folder within an IMAP account directory Using Outlook 1
A Creating archive rule on the clients by script/ Outlook VBA and Custom Forms 3
J Creating a URL from a message body excerpt before forwarding Using Outlook 2
B Need Help Creating Email Based on Subject w Address in Body Outlook VBA and Custom Forms 1
A Creating rule to create week folder and transfer mail using alert Using Outlook 3
J Creating an "isolated" shared calendar in Outlook Outlook VBA and Custom Forms 1
L Creating a Task from Email and Attaching Original Email Outlook VBA and Custom Forms 6
S Creating custom rule to move if "NAME" is in body but ignore the phrase "Hi NAME" in the search Using Outlook 2
witzker Outlook bug when creating a user defined contact form? Using Outlook 1
G Creating an Outlook Rule using Internet Header time Using Outlook 1
Wotme Creating a Outlook task in Excel Using Outlook 7
V Need to add some text in subject while creating new mails - NEED VB CODINGS Using Outlook 4
G Questions on creating Outlook forms Using Outlook 0
P Creating custom contact forms Using Outlook 2
K Outlook 2010 creating extremely large PST files for IMAP accounts Using Outlook 3

Similar threads

Top