Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-26-2018, 07:11 AM
donaldadams1951 donaldadams1951 is offline Insert RTF file into existing document Windows XP Insert RTF file into existing document Office 2010 32bit
Advanced Beginner
Insert RTF file into existing document
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default Insert RTF file into existing document

I have a macro that creates a RTF file based on information in a database in the background and saves it. It formats the text with bold and font size, etc. I format the text with 12 point font size and other parts 10 point. If I open the rtf I created it has all the formatting I told it to use. The problem is that when I insert it into the an existing document it changes the font size to 10 point on all the text in the inserted document. I need it to hold the existing formatting after it is inserted. I have in the Options/Advanced/Cut, Copy and Paste to keep Source formatting but it does not.
Any idea what might be going on?

Here is a portion of the macro..

' open document
Set objDoc = objWord.Documents.Open(StrTempPic)

Set objSelection = objWord.Selection

' if not the first report, double space
If rownum > 1 Then
objSelection.TypeText (vbNewLine & vbNewLine)
End If

objSelection.Font.Bold = True
objSelection.Font.Size = "12"

objSelection.TypeText ("Report Name: ")

' format Report Name
objSelection.Font.Bold = False
objSelection.Font.Size = "10"
objSelection.Font.Underline = True

' Report Name, underlined
'objSelection.TypeText (rs(1) & ", ")
objSelection.TypeText (rs(1)) & ","

' turn off underline
objSelection.Font.Underline = False



' the rest of the line is not underlined, titles will be bold

' Version
objSelection.Font.Bold = True
objSelection.TypeText (" Version: ")
objSelection.Font.Bold = False

objSelection.TypeText (rs(2) & ", ")

'Instance number
objSelection.Font.Bold = True
objSelection.TypeText ("Inst#: ")
objSelection.Font.Bold = False

objSelection.TypeText (rs(3) & vbNewLine & vbNewLine)

objDoc.Save
objDoc.Close

' MsgBox ("Just saved document")

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''

' move to "efrm goes here" section
' it will only be here on the first document insertion

startTag = "\[EmbeddedReport\]"
endTag = "\[/\EmbeddedReport\]"

strSearchString = startTag & "efrm goes here" & endTag


' MsgBox ("SearchString = " & strSearchString)

With Selection.Find
.ClearFormatting
.Text = strSearchString
.Replacement.ClearFormatting
.Replacement.Text = "[EmbeddedReport" & ReportInstance & "]efrm goes here[/EmbeddedReport" & ReportInstance & "]"
' MsgBox Selection.Find.Replacement.Text

.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
End With

' end select it
Selection.Find.Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue

Selection.HomeKey Unit:=wdStory

With Selection.Find
.ClearFormatting
.Text = "efrm goes here"
.Replacement.ClearFormatting
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
End With

Selection.Find.Execute ' Replace:=wdReplaceAll ' , Forward:=True ' , Wrap:=wdFindContinue

Selection.InsertFile StrTempPic
Reply With Quote
  #2  
Old 06-26-2018, 04:18 PM
macropod's Avatar
macropod macropod is offline Insert RTF file into existing document Windows 7 64bit Insert RTF file into existing document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Undoubtedly, you have a Style conflict between whatever Style is in use in the RTF (Word will assume the 'Normal' Style if none is specified) and the corresponding Style in Word. Instead of going about things as you are now, you might consider not applying your formatting to the RTF and, instead, format the content via appropriately-defined Styles once it's been imported into Word.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
formatting, rtf

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert a pdf file into a word document raistlin Word 2 01-08-2014 01:42 PM
Insert RTF file into existing document Best way to insert sub-document into existing document lsmcal1984 Word 7 08-21-2013 11:11 PM
How to insert full documents into existing word document Laraak Word 1 03-07-2013 11:59 PM
How to insert a .mov file in Word Document Jai25 Word 0 02-11-2010 04:40 PM
How to insert a reference to an existing endnote dwschulze Word 0 01-23-2010 08:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft