Solved

VB Script in Outlook 2010

Posted on 2013-12-30
6
337 Views
Last Modified: 2014-06-18
Hello,

From my custom Outlook form, I have a script that pulls the data from a SQL field that was just a text field to a Bookmark field in a Word doc.  It's worked fine.  

Now the definition of that same field in SQL was changed so that it could contain formatting information.  When I pull the data now, it pulls all the formatting garbage with it.  How can I just pull in the text that I want to see?  It can be plain text, or with the formatting, I don't care.

My code goes like this:

          rst.Open "Select BEZ FROM BW_AUFTR_KTXT WHERE TEXT_ID = 25 and ID = '" & Trim(Item.UserProperties("JobNumber").Value) & "'", _
          oADOConn, adOpenKeyset, adCmdTable

objDoc.Bookmarks("Notes").Range.InsertBefore Trim(rst("BEZ"))

But instead of pulling in "asdf", it pulls over this:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}}
{\colortbl ;\red0\green0\blue0;}
{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\tx640\tx1280\tx1920\tx2560\tx3200\tx3840\tx4480\tx5120\tx5760\tx6400\tx7040\tx7680\tx8320\tx8960\tx9600\tx10240\tx10880\tx11520\tx12160\tx12800\tx13440\tx14080\tx14720\tx15360\tx16000\tx16640\tx17280\tx17920\tx18560\tx19200\tx19840\tx20480\cf1\f0\fs20 asdf\par
}


Thanks for your help,
Joel
0
Comment
Question by:Genius123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39747465
What happens if you try the value property i.e.

objDoc.Bookmarks("Notes").Range.InsertBefore Trim(rst("BEZ").value)

Chris
0
 

Author Comment

by:Genius123
ID: 39751796
Nothing changed....  Maybe there is some function like this?...


e.g.   objDoc.Bookmarks("Notes").Range.InsertBefore FormatFromRichTextToPlainText(rst("BEZ")
0
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39988036
Hi,

You could use this to transform your Rtf in Plain text ( With reference to MS HTML Object library)

Function fRTF2Text(sRTF As Variant) As Variant
  Dim oDoc As HTMLDocument
If IsNull(sRTF) Then
    fRTF2Text = Null
Else
  Set oTxt = New HTMLDocument
  oTxt.body.innerHTML = sRTF
  fRTF2Text = oTxt.body.innerText
End If
End Function

Open in new window

Regards
0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 39990395
@rgonzo.  just tested that out of interest and it does not work for richtext....

only methods i have seen use MSWord as the convertor. given you have a reference to oDoc already this may be of use... stackoverflow
0
 

Author Closing Comment

by:Genius123
ID: 40143490
That worked, thanks.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question