Link to home
Start Free TrialLog in
Avatar of Tom Crowfoot
Tom CrowfootFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Manipulate RTF doc from Access

Dear Experts

I am trying to join up some VBA from Access & from Word ... basically I want to be able to open an RTF doc from Access,  run a macro on it and then close it down

The word part works in the rtf doc all fine but I can't seem to get the code to open up the rtf doc & haven't looked at the saving the rtf doc yet.  this is the code I have so far - I keep getting a compile error "User-defined type not defined"

Can anybody help?

Private Sub Command3_Click()
'open up RTF doc bit
    
    Dim objWord As Word.Application
    Dim docWord As Word.Document

    Set objWord = CreateObject("Word.Application")
    Set docWord = objWord.Documents.Add("C:\Users\xxxxx\Desktop\CiP-Client Interviews 1.rtf", False)
    objWord.Visible = True
    
'manipulate RTF doc bit
    With ActiveDocument
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Bold = True
    With Selection.Find
        .Text = "(||)(*)(\>\>)"
        .Replacement.Text = "\2"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

' Save & close bit to go here
    End With

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Crowfoot

ASKER

Brilliant - thank you very much - I forgot to add the reference to word!
You are welcome!

/gustav