Manipulate RTF doc from Access

Posted on 2013-09-30
Medium Priority
Last Modified: 2013-09-30
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.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

Question by:correlate
  • 2
LVL 53

Accepted Solution

Gustav Brock earned 2000 total points
ID: 39533341

Dim objWord As Object
Dim docWord As Object

or (better) go to Tools, References and add a reference to Word.


Author Closing Comment

ID: 39533383
Brilliant - thank you very much - I forgot to add the reference to word!
LVL 53

Expert Comment

by:Gustav Brock
ID: 39533401
You are welcome!


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
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.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

587 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