help passing textBox values to Word from autocad

J

John Coon

I have a Autocad form for marking paint on a runway. what I'd like to do is
use the data from the form to create a QTO report in word.
This section of code launches word and places text into the word document.
The problem I have is that I don't know how to pass the
values from the form TextBoxes in Autocad into the insert text part in word.

This is my first attemp using word

Thank you for any direction you can give,
John Coon

sample TextBox Values:
TextBox7 = 150
TextBox8 = 5.75
Should print as "This is a test for a value from a textBox = 150 x 5.75"


'Pass TextBoxes from autocad

Private Sub CommandButton2_Click()
Hide

On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add
Set mywdRange = myDoc.Words(1)
With mywdRange
.Text = "This is a test for a value from a textBox " & _
"value = TextBox7 x TextBox8"
.Font.Name = "Comic Sans MS"
.Font.Size = 12
.Font.ColorIndex = wdBlack
.Bold = True
End With
errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing

End Sub
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi John,

I don't have an experience of automating autocad, but it is more likely to
be

.Text = "This is a test for a value from a textBox " & TextBox7 & " x "
& TextBox8


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
J

John Coon

Doug,
That was it! Thank you for your help.
In word vba how do you add additional sentences to the .text. In my sample
I had only one .text statement, I added a few more lines of .text to test
after reading your help instructions. When I run routine it only placed the
last .text call into the word doc. How to you control how many lines can be
inserted?

Also could you direct me to any material that talks about the placement of
bookmark. From what I was able to read/find in the ng the bookmark is how
you place text values in a controlled location.

Again Thank you for your time and direction.

John Coon


"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi John,

To insert additional sentences, you would just include them in the string,
separating them with & vbCr & to force a separate paragraph. For example

ActiveDocument.Bookmarks("test").Range.InsertBefore "The quick brown fox
jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The
quick brown fox jumps over the lazy dog. The quick brown fox jumps over the
lazy dog. The quick brown fox jumps over the lazy dog." & vbCr & "The quick
brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy
dog. The quick brown fox jumps over the lazy dog. The quick brown fox
jumps over the lazy dog. The quick brown fox jumps over the lazy dog."

which was all on one line in the Visual Basic Editor, inserts the following
into the document inside the bookmark "test"

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.

See the article “Working with Bookmarks in VBA” at:

http://word.mvps.org/FAQs/MacrosVBA/WorkWithBookmarks.htm


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
J

John Coon

Doug,

Thank you for explaining the format. having never used word vba I looked at
many samples from the ng but didn't see any that fit what I was trying to do
or because it was word I didn't understand very well what they were actually
doing.

Again thank you, Have a great day!
John Coon.

,
"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 
J

John Coon

Doug,

In you first reply: you said to use this format for insert text from
Texboxes.
I don't have an experience of automating autocad, but it is more likely to be
.Text = "This is a test for a value from a textBox " & TextBox7 & " x
" & TextBox8

? Is there a way to keep the above format for multiple sentences, like
below. The entire document consists of more of a bill of materials like feel
with every line of text being generated from the dialog userform1. from what
I could see if I used a bookmark wouldn't I have to point to a template that
already had the bookmarks. I'd like to have the routine run so I and others
could use it from any machine or am I wrong about the bookmarks.

I thought about using a creating a text file with Open
"C:\temp\filename.txt" For Output As #1, Print #1, TextBox7 & "," &
TextBox8 and so on but I wanted to get this into word. if at all possible
without a template to point to. As long as the text is inserted the user
can apply other text formatting if they choose to at a later date.

There is no way in word to place text in this type of format without
creating a huge string as in your late post?

..Text = "Runway Edge Length = " & TextBox33 & " sq Ft"
..Text = "Runway Edge Width = " & TextBox33 & " sq Ft"
..Text = "Runway Edge Total Square Footage = " & TextBox33 & " sq Ft"


Private Sub CommandButton2_Click()
Hide

On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add
Set mywdRange = myDoc.Words(1)
With mywdRange

..Text = "Runway Edge Length = " & TextBox19 & " sq Ft"
..Text = "Runway Edge Width = " & TextBox20 & "
..Text = "Runway Edge Total Square Footage = " & TextBox21 &

..Text = "Runway ThresHold Length = " & TextBox22 &
..Text = "Runway Theshold Width = " & TextBox23 &
..Text = "Runway Threshold Total Square footage = " & TextBox24 & " sq Ft"
'....more


.Font.Name = "Comic Sans MS"
.Font.Size = 12
.Font.ColorIndex = wdBlack
.Bold = True
End With
errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing

End Sub














"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi John,

Going back to your initial post, I see that you are creating a new blank
document (myDoc) and then setting mywdRange to myDoc.words(1). That means,
that you are inserting this information at the start of a blank document.

That being the case, you can use

Set myDoc = wdApp.Documents.Add
myDoc.Range.InsertAfter "Runway Edge Length = " & TextBox19 & " sq Ft" &
vbCr
myDoc.Range.InsertAfter "Runway Edge Width = " & TextBox20 & " sq Ft" & vbCr
etc

Rather than creating a large string and then inserting it all in one go.


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
J

John Coon

Doug,

!!!! That is exactly what I was looking for... Word seems more of a bear
than AutoCAD. I thought coordinate systems were difficult until I came to
use word.. AutoCAD has hundreds of sample file, usually you can find
something that match or at least comes close to give you a fighting chance.
Having had a chance to use word vba I think I will use this method for all
my printouts. Thank you.

Thank you for your time and understanding trying to help a non-word person
with some vba,
John Coon

"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 

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