Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import RTF to WORD with Styles Or Export Access Rpt to RTF with styles

Status
Not open for further replies.

mych

Programmer
May 20, 2004
248
GB
I currently output a series of reports as RTF's and then import them into a Word97 file. The RTF's contain a single line Heading and then a paragraph or two of text.

These import into the WORD document correctly with the heading in 14pt Times Bold and the rest in 12pt Times Normal as set in the Access Report.

One of the things I need to do to the WORD document is update the Table of Contents after the RTF's have been imported. The TOC will look for the Word style HEADING 1. Unfortunatly the RTF's, (even though import in the correct type, size and weight), are in the style NORMAL.

Is there a way of setting the syle of a paragraph at output (Access Report to RTF) or input (RTF to WORD) stage?

Any help appreciated

Mych
 
Take a look at Word's Format, Autoformat which can look at formatting and apply styles.
 
Cheerio, Thanks

I opened my rtf's and used the AutoFormat as General Document and it did the trick.

Now I could do with some help trying to figure out haw to include this into my code.

The code I have is...

Code:
Set fs = Application.FileSearch
With fs
    .LookIn = RTFLoc                'RTFLoc stored the Path and Directory where the rtf's are stored
    .FileName = "*.rtf"             'This will search for all .rtf files and sort them in alfa order
    If .Execute(SortBy:=msoSortByFileName, _
    SortOrder:=msoSortOrderAscending) > 0 Then
        For i = 1 To .FoundFiles.Count - 1         'For each rtf starting with the first to last but one
            strRTF = "Rpt" & i & ".rtf"            'Find the text and replace it with the contents of the rtf
                Selection.Find.ClearFormatting
                With Selection.Find
                    .Text = "Insert First Project Requirement Here 257017710752"
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Format = True
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                End With
            Selection.Find.Execute
            Selection.Delete Unit:=wdCharacter, Count:=1
            ChangeFileOpenDirectory RTFLoc
            Selection.InsertFile FileName:=strRTF, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
            
            'Now insert pagebreak and text so that the next rtf is inserted in the correct place.(The 'bookmark')
            Selection.InsertBreak Type:=wdPageBreak
            Selection.TypeText Text:="Insert First Project Requirement Here 257017710752"
            'Cycle through to next rtf.
        Next i
            'With the last rtf we just need to insert the rtf no need to insert the 'bookmark'
             strRTF = "Rpt" & i & ".rtf"
                Selection.Find.ClearFormatting
                With Selection.Find
                    .Text = "Insert First Project Requirement Here 257017710752"
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                End With
            Selection.Find.Execute
            Selection.Delete Unit:=wdCharacter, Count:=1
            ChangeFileOpenDirectory RTFLoc
            Selection.InsertFile FileName:=strRTF, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
        
    Else
        MsgBox "There were no files found."     'Message box displayed is no RTF's found
    End If
End With

End Sub

This sub when called will check a directory for rtf files. It will then take them one at a time and insert then in the word document.

Any Ideas?

Mych
 
Update...

I have stuck the following

Code:
Selection.Range.AutoFormat

after the lines

Code:
Selection.InsertFile FileName:=strRTF, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False

in the above code.

This does the autoformat but seems to do it on the whole document and not of the inserted text.

Any ideas on how to insert the rtf file and then perform the AutoFormat on the inserted text only.

Thanks in advance.

Mych
 
I have been away a couple of days.

Logically, what it seems you need to do is to open each rtf file in turn as a separate word doc, and autoformat it.

Then when you bring that file into the parent doc it will have a style defined.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top