View Full Version : Office Automation Send Rich Text from Access to Word
Movian
08-18-2009, 02:37 PM
Hey,
im working heavily with office automation. I have a requirement to have Rich text sent to word through my existing bookmark replacement system.
This is so that a paragraph that is formatted in rich text (Through the use of HTML) can have for example a bold header etc.
When i manually copy and paste the text from the box to word it retains the formatting :) perfect.
When i use automation and send the stored value in the table to word it reads <strong> Header </strong> instead of actually being bold like THIS
However again if i copy the text directly from the table manually and paste it into word it works fine.... how can i use automation to send the value of this field to word and retain the formatting of the rich text created by the HTML (i can use something other than HTML to create the formatting if that will help)
As always i appreciate any help offered :)
If you set up the Word Doc with a Bookmark and set the Bookmark to Bold it will transfer the data as Bold, see the attached word doc which I have just sent to from Access.
Movian
08-19-2009, 10:20 AM
The problem is i have a single field going to a single book mark andi require parts of this single book mark to be bold and others to not be... :(
Movian
08-19-2009, 11:29 AM
well are there any scripting codes that word knows ? somthing like bbcode or html ? that i can insert to just set it as bold when i need it ?
I don't know if this helps or not, but it orked for me.
m_objWord.Selection.Text = "Is this Bold"
m_objWord.Selection.Font.Bold = True
Movian
08-20-2009, 06:22 AM
Well that would change the text in word to bold.... now i just need to figure out how to highlight/select that text
Alternativly it looks like there is a Set RTF syntax i should be able to use
http://www.xtremevbtalk.com/showthread.php?t=148507
However as usuall Microsoft has decided it would be too easy to just let me do that as it appears that the RichText box does not allow the use of STANDARDIZED RICH TEXT !!!!! sorry , a little venting there
Tommy
08-25-2009, 06:31 AM
Movian,
Once you get the text in the bookmark you can collapse the range, look for the <strong> select the words and set the font to bold as OBP has suggested.
If you will post a sample string I will see what I can come up with. I don't have Access to play with so I will have to do it from Excel to Word.
Movian
08-25-2009, 12:20 PM
<Strong>Documentation for the first unit of 36479 (36479x1-RT) an anatomically separate saphenous vein treated through a separate access site.</Strong>
Access site number 1 is described in words as percutaneous separate access site that is a tributary anatomoses with the GSV. The vein was accessed via a 20 gauge cannula. Access site is 16 cm from the sole of the foot. I treated a 4.5mm mm in diameter vessel 10cm cm in length. It was treated with 10 Watts at 30 Hz. I used a manual pullback at 0.5 mm/sec. There were 3544 pulses used and 64531 joules per cm over 6 seconds. I used 100 Mj/pulse. Vein closure was documented via ultrasound. I used a 600 micron fiber.
<Strong>Documentation for the second unit of 36479 (36479x2-RT) an anatomically separate saphenous vein treated through a separate access site.</Strong>
Access site number 2 is described in words as percutaneous separate access site that is a tributary anatomoses with the GSV. The vein was accessed via a 4 french microintroducer. Access site is 23 cm from the sole of the foot. I treated a 5.5mm mm in diameter vessel 10cm cm in length. It was treated with 10 Watts at 30 Hz. I used a manual pullback at 0.5 mm/sec. There were 651 pulses used and 68754 joules per cm over 10 seconds. I used 100 Mj/pulse. Vein closure was not documented via ultrasound. I used a 600 micron fiber.
This paragraph will replicate itself an unspecified number of times, keep the same lay out but modified values
Tommy
08-25-2009, 02:02 PM
OK here is my attempt I got it to work in Word, the <Strong> </Strong> is still in the document, not trying to tell you what to do but .Find will find them and remove them. :)
I have unneccessary dims and some other fat not removed. This is brute force, first round, I will tweek if necessary. SmplStr is the paragraph's you posted.
Sub Movian(SmplStr As String)
Dim Bld As Range, St As String, En As String
Dim Fin As Long, FinEn As Long
St = "<Strong>"
En = "</Strong>"
Set Bld = ActiveDocument.Bookmarks("BgPara").Range
Bld.Text = SmplStr
ActiveDocument.Bookmarks.Add "BgPara", Bld
Fin = InStr(1, ActiveDocument.Bookmarks("BgPara").Range.Text, St)
While Fin > 0
FinEn = InStr(Fin, ActiveDocument.Bookmarks("BgPara").Range.Text, En)
ActiveDocument.Bookmarks("BgPara").Range.Collapse Direction:=wdCollapseStart
Selection.MoveRight wdCharacter, FinEn - Fin, wdExtend
Selection.Font.Bold = True
Fin = InStr(FinEn, ActiveDocument.Bookmarks("BgPara").Range.Text, St)
If Fin > 0 Then Selection.MoveRight wdCharacter, Fin - FinEn, wdMove
Wend
End Sub
Tommy
08-26-2009, 07:06 AM
OK I ran this from excel, the counts may need to be adjusted for the number of blank lines between bold and non bold.
Sub BldTxtBkMk(SmplStr As String, BrkMk As String, WrdDoc As Document, iWrd As Word.Application)
Dim Bld As Word.Range, St As String, En As String
Dim Fin As Long, FinEn As Long
St = "<Strong>"
En = "</Strong>"
Set Bld = WrdDoc.Bookmarks(BrkMk).Range
Bld.Text = SmplStr
WrdDoc.Bookmarks.Add BrkMk, Bld
iWrd.Selection.Goto What:=wdGoToBookmark, Name:=BrkMk
iWrd.Selection.StartOf Unit:=wdSentence, Extend:=wdMove
Fin = InStr(1, WrdDoc.Bookmarks(BrkMk).Range.Text, St)
While Fin > 0
FinEn = InStr(Fin, WrdDoc.Bookmarks(BrkMk).Range.Text, En)
iWrd.Selection.MoveRight wdCharacter, 8, wdExtend
iWrd.Selection.Delete
iWrd.Selection.MoveRight wdCharacter, (FinEn - Fin) - 8, wdExtend
iWrd.Selection.Font.Bold = True
iWrd.Selection.MoveRight wdCharacter, 1, wdMove
iWrd.Selection.MoveRight wdCharacter, 9, wdExtend
iWrd.Selection.Delete
Fin = InStr(FinEn, WrdDoc.Bookmarks(BrkMk).Range.Text, St)
'this line may need to be adjusted for line counts
If Fin > 0 Then iWrd.Selection.MoveRight wdCharacter, (Fin - FinEn) + 8, wdMove
Wend
End Sub
Sub Testing()
Dim Wrd As Word.Application, mText As String
Dim WrdDoc As Document
Set Wrd = GetWrd
Wrd.Visible = True
Set WrdDoc = Wrd.Documents.Open("C:\dell\Erg.doc")
mText = "<Strong>Documentation for the first unit of 36479 (36479x1-RT) " & _
"an anatomically separate saphenous vein treated through a separate " & _
"access site.</Strong> " & vbCrLf & vbCrLf & _
"Access site number 1 is described in words as percutaneous separate " & _
"access site that is a tributary anatomoses with the GSV. The vein was " & _
"accessed via a 20 gauge cannula. Access site is 16 cm from the sole of the " & _
"foot. I treated a 4.5mm mm in diameter vessel 10cm cm in length. It was treated " & _
"with 10 Watts at 30 Hz. I used a manual pullback at 0.5 mm/sec. There were 3544 " & _
"pulses used and 64531 joules per cm over 6 seconds. I used 100 Mj/pulse. Vein " & _
"closure was documented via ultrasound. I used a 600 micron fiber." & vbCrLf & vbCrLf & _
"<Strong>Documentation for the second unit of 36479 (36479x2-RT) an anatomically " & _
"separate saphenous vein treated through a separate access site.</Strong>" & vbCrLf & vbCrLf & _
"Access site number 2 is described in words as percutaneous separate access site " & _
"that is a tributary anatomoses with the GSV. The vein was accessed via a 4 french " & _
"microintroducer. Access site is 23 cm from the sole of the foot. I treated a 5.5mm mm " & _
"in diameter vessel 10cm cm in length. It was treated with 10 Watts at 30 Hz. I used a " & _
"manual pullback at 0.5 mm/sec. There were 651 pulses used and 68754 joules per cm over 10 " & _
"seconds. I used 100 Mj/pulse. Vein closure was not documented via ultrasound. I used a 600 " & _
"micron fiber."
BldTxtBkMk mText, "BigBkMk", WrdDoc, Wrd
End Sub
Function GetWrd() As Word.Application
On Error Resume Next
Set GetWrd = GetObject(, "Word.Application")
If Err.Number > 0 Then
Err.Clear
Set GetWrd = CreateObject("Word.Application")
End If
On Error GoTo 0
End Function
Movian
08-31-2009, 11:32 AM
Thanks Tommy! :D
That looks like it will do just what i need... i may even be able to expand on it to utilize additional HTML functions for text formatting.....
Mabye il even create a sub for the MADV :D
I haven't tested this out yet but i fully intend to and i will let you know how it goes.
Tommy
08-31-2009, 12:46 PM
What is the MADV?
I'm a little slow today LOL
Movian
08-31-2009, 12:55 PM
The MADV (Movian's Access Development Kit)
Its currently in its Alpha release and under heavy development.
You can download the Alpha from here
http://www.appdepot.co.uk
from developer kits. Also if you would like to put any projects up on that site for download then let me know :)
Tommy
08-31-2009, 01:26 PM
I'm blocked from work, that is how they get me to count ALL of the bolts. LOL
I had followed the thread for a while and then it disappeared. I'll get it when I get home tomorrow, thanks!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.