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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble with sending to word from access

Status
Not open for further replies.

dmodele

Technical User
Jul 30, 2002
19
0
0
US
Im working on a project that involves creating dynamic documents an access module from tables and then sending the content to word documents and I got stuck in a very early stage...

As a first step/test, I tried to just open up an instance of word, open up the pre-formatted starting word document, and then "save as" to a new title. Eventually, I will be replace some text etc.. but for now I just wanted to see that I could open the document and properly do the save as. The problem I ran into is that when I looked at the saved document and compared it to the original, I noticed that all the formatting was gone... every line was center aligned, the fonts were all the same, nothing was bolded.. basically, I lost all the formatting. I have no idea what I did wrong.. can someone help? here is the code that I used:

------------------------------------------------------
Private Sub Test_Click()

Set WordInst = CreateObject("word.application")
Set WordDoc = WordInst.Documents.Open("C:\Documents and... ...Settings\dmodele\Desktop\nifty\templateDEMOGRAPHICS.doc")
c = WordDoc.content

'some code that I will do to the content, some replaces mostly

WordDoc.content = c
WordDoc.SaveAs ("C:\Documents and... ...Settings\dmodele\Desktop\nifty\Demographics.doc")
WordDoc.Close
WordInst.Quit

End Sub
------------------------------------------------
what am I missing? please help!
 
c = WordDoc.content
The Document.Content property return a Range object,
so the coorect syntax is:
Set c = WordDoc.Content
Your code assign the default Text property of the range object to c, so loosing all the formatting stuff.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

I tried replacing the line:

c= WordDoc.content

with the line:

Set c=WordDoc.Content

and still the code does the exact same thing. Maybe I didnt understand what you posted.. I looked at the properties available to the class "range" and didnt find any property that included both the content and the formatting. Is there something I have to add to the code to capture the text and the formatting?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top