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

Inserting formatted text into Word Document 1

Status
Not open for further replies.

twomblml

IS-IT--Management
Apr 17, 2001
42
US
Looking for advice here...

I am trying to build some functionality into Access for users to select snippets of formatted text to insert into a Word document. I would like to present the user with a selection form to click checkboxes for what text to include on the document. Once checked, click a button to send over the snippets of text into a final Word document. I have the whole Access to Word Mail Merge process working however I am having problems with keeping the format of the text. Formating includes bullets, returns, bold, italics, etc...

Where is the best location to store and retrieve the formatted text?

Thanks!
 
is it possible to have each snippet as separate word docs, then open the required snippets via a word object variable as well as a masterr doc and do some merge or copy/paste from one to other, which hopefully will keep the formating as is.

Which should generate your final master doc.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Based on 1DMF's inspiration I have decided to go the route of using bookmarks. So I have a main document with a bookmark for each snippet. I copy the snippet depending on what bookmark I want and I'm trying to paste the contents into another document that already has text. I would like to just paste the text at the end of the document. I have the copy routine working but it will not paste. If I do a manual paste it works without issue. Here is my code, any suggestions are greatly appreciated! Thanks

Dim mBookmark As Bookmark

Dim objWord As New Word.Application
Dim objDoc As Word.Document
Dim objDocTemp As Word.Document

Set objDoc = objWord.Documents.Open("F:\OCC Subcontractors\Scope.doc")
Set objDocTemp = objWord.Documents.Open("F:\OCC Subcontractors\Scope Template.doc")
objDocTemp.Application.Visible = True

Set objDoc = ActiveDocument
objWord.Application.Documents.Add

objDoc.Activate

For Each mBookmark In objDoc.Bookmarks()
If mBookmark.Name = "SECTION4" Then
mBookmark.Select
Selection.Copy
objDocTemp.Activate
Selection.Paste
objDoc.Activate
End If
Next

objDoc.Close

Set objDoc = Nothing
Set objDocTemp = Nothing
Set objWord = Nothing
 
You haven't select anything before the paste.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
hmm, is it maybe it is holding it on a "clipboard" relative to each worddoc.

So objDoc & objDocTemp cannot see each others "copy data" so when you paste it is blank.

is there a way to copy the data into a variable and paste the variable to the other doc?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
PHV was correct it wasn't selecting. To many changes this morning before coffee. Now I have it selecting, copying and pasting into the correct document. However it pastes at the beginning of the document. I want it to past at the end of the document. How can I specify this? I don't want a line number because it could change.

Thanks!
 
so bookmark.select wasn't working?

I was having a play and another way to do this could be

Code:
Set objDocTemp = ActiveDocument

ActiveDocument.Bookmarks.Add ("SECTION4")

objDocTemp.Bookmarks("SECTION4").Range.Text = objDoc.Bookmarks("SECTION4").Range.Text

would doing a bookmark insert automatically start at end of document




"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
1DMF I guess I don't really understand your method above. Yes the bookmark.select was not working but it is working great now. I could be pasting multiple snippets to this document and I want each snippet to be pasted into the document at the end.

Thanks for all the suggestions so far!
 
basicaly you keep both docs open, activate the one to be the master, add the bookmark you want and then copy the bookmarks from one to the other.

I think as you add each bookmark to the new doc being created they are added to the end of the doc /where the cursor is.

But you will need to check on that, if not is there not a simple way of making the document you want active and then issuse a "GOTO END" command or simulate the end key being pressed?

must dash - friday, home time, i'm off down the pub, have a great weekend,

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I want it to past at the end of the document.
Before the call to the Paste method:
Selection.EndKey Unit:=wdStory

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Brilliant PHV! The spec on this monster keeps changing, I don't know if I'll be able to continue the copy paste routines because I need to paste more text into different locations on the document. PHV is there a better way to do this?
 
Can you have a master blank document with nothing but bookmarks in it and then use the method I showed to make one bookmark = another.

So if you had bookmarks 1-10 and you put stuff in 3 5 9 , you could easily then put more stuff before, inbetween or after existing bookmark texts.

Just a thought.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
1DMF thanks for the suggestion. I am using a bit of your suggestion in my code. I am copying one bookmark to another but its not holding the formatting when inserted into the new document.

Any ideas?

Thanks
 
well if the copy bookmark is not keeping formating, one would suggest that the bookmark does not contain the formating. hmmm

Does the straight copy/past from selection hold format ok.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
The formatting is working properly now. The only thing that has me fumbling around is I need to paste portions of text in order. Whenever I past text into a bookmark multiple times it puts the latest text in the top of the bookmark instead of at the bottom. I can't put multiple bookmarks because sometimes I don't paste text into some of the bookmarks. This leaves gaps in my text.

I have been trying to use the .moveend to move to the end of my range and insert a new bookmark so next time I come and paste text the text gets inserted last but this is not working properly.

Thanks for the assistance so far.
 
I have been able to get this to work by storing some items in a 2d array and running a sort on the array. Thanks for all the help.
 
glad you got it sorted :D

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top