Compiling a document when selecting data from a table I got many undeasirable return

R

rija

Hi Folks,

What I mean is that I had created a document with a macro program,
that allow me to personalize my document using a form and selecting
datas from tables using Documents.Open(FileName:="c:\Table.doc") then
when I display the data in the document, after each field, the
document insert a return chariot although I do not want such a mess.
So what's wrong with my program? and how can I get rid of it?

The program is display as following:

Dim texto(11) As String

Private Sub ComboBox1_Enter()
Dim sourcedoc As Document, i As Long, myitem As Range

Set sourcedoc = Documents.Open(FileName:="c:\worddocs\TestTable.doc")
For i = 0 To sourcedoc.Tables(1).Rows.Count
Set myitem = sourcedoc.Tables(1).Cell(i + 1, 1).Range
texto(i) = sourcedoc.Tables(1).Cell(i + 1, 2).Range

myitem.End = myitem.End - 1
ComboBox1.AddItem myitem.text
Next i
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges

End Sub

Private Sub CommandButton1_Click()
Dim ComboBox As String

If TextBox1 <> "" Then

If Textbox2 <> "" Then
Textbox2 = " jusqu'au " + Textbox2
With ActiveDocument
.Bookmarks("Text2").Range _
.InsertBefore Textbox2

End With
End If
MsgBox (ComboBox1)
Select Case ComboBox1
Case "Accident"
ComboBox = texto(0)
Case "Airport"
ComboBox = texto(1)
Case "Cold and flue"
ComboBox = texto(2)
Case "Death"
ComboBox = texto(3)
Case "Visit"
ComboBox = texto(4)
Case "Family problem"
ComboBox = texto(5)
Case "Forgot"
ComboBox = texto(6)
Case "Malaria"
ComboBox = texto(7)
Case "Tiredeness"
ComboBox = texto(8)
Case "Transportation"
ComboBox = texto(9)
Case "Trip"
ComboBox = texto(10)
End Select

With ActiveDocument
.Bookmarks("Text0").Range _
.InsertAfter Trim(ComboBox)

End With

With ActiveDocument
.Bookmarks("Text1").Range _
.InsertBefore TextBox1
End With
UserForm1.Hide
End If
End Sub


Cheers
Rija
 
C

Cindy M -WordMVP-

Hi Rija,
What I mean is that I had created a document with a macro program,
that allow me to personalize my document using a form and selecting
datas from tables using Documents.Open(FileName:="c:\Table.doc") then
when I display the data in the document, after each field, the
document insert a return chariot although I do not want such a mess.
So what's wrong with my program? and how can I get rid of it?
It's difficult when you don't "Reply" to the thread where a discussion
started. If I understand you correctly, when you insert data from a
UserForm into your document you're getting undesirable symbols?

Looking through your code, I see that you assign
text0(i) = sourcedoc.Tables(1).Cell(i + 1, 2).Range

If one used strict typing rules, this would be syntactically incorrect,
as text0(i) should probably be a STRING type. OK, VBA is generous and
figures you really want to use the default .Text property for the
range.

But keep in mind that a Cell.RANGE includes the end-of-cell marker,
which is (roughly) Chr(13)&Chr(7). And when this goes through a
conversion to a VBA string variable, then dropped back into a Word
document, what you get at the very least is an extra paragraph mark,
and possibly a little "box" character, in addition.

So you should at least use
TrimRight(sourcedoc.Tables(1).Cell(i + 1, 2).Range.Text)

Or, if that doesn't work, then
Left(sourcedoc.Tables(1).Cell(i + 1, 2).Range.Text,
Len(sourcedoc.Tables(1).Cell(i + 1, 2).Range.Text) - 1)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top