PDA

View Full Version : [SOLVED:] want specific output in word but in terms of vba code



mbbx5va2
03-23-2014, 01:30 PM
Hi

I am trying to insert a text box in the word document so that I can write an address so that the word document is in letter format. Also I want to put the data into 3 separate tables. I can do this in word but wanted to know how to amend the code below to create the letter output. If anyone can amend the data below and put any of it inside a text box with edges colored white or inside a table then that should be enough.

Using the following code I have created the attached word document:


'Send commands to Word With WordApp
.Documents.Add
With .Selection
.Font.Size = 14
.Font.Bold = True
.ParagraphFormat.Alignment = 1
.TypeText Text:="ULFP project lead sheet"
.TypeParagraph
.TypeParagraph
.Font.Size = 12
.ParagraphFormat.Alignment = 0
.Font.Bold = False
.TypeText Text:="Date:" & vbTab & _
Format(Date, "mmmm d, yyyy")
.TypeParagraph

.TypeText Text:="Policy Number:" & vbTab & Region

.TypeParagraph

.TypeText Text:="ID: VA78747"

.TypeParagraph

.TypeText Text:="Surnames:" & vbTab & Surname

.TypeParagraph
.TypeParagraph
.TypeParagraph

.TypeText Text:="Remediation Amount:" & vbTab & Remediation

.TypeParagraph

.TypeText Text:="Interest:" & vbTab & Inte

.TypeParagraph

.TypeText Text:="Taxation:" & vbTab & Ta

.TypeParagraph

.TypeText Text:="Total Remediation Amount:" & vbTab & TotalRem

.TypeParagraph
.TypeParagraph
.TypeParagraph
.TypeText Text:="Transaction type:" & vbTab & "Cheque"
.TypeParagraph
.TypeText Text:="Payee Name:" & vbTab & Pay


.TypeParagraph

End With

Any thoughts? :think:

fumei
03-23-2014, 01:50 PM
The attached document is not helpful. What would be helpful is a document showing what you want it to look like.

mbbx5va2
03-23-2014, 02:04 PM
Hi

Thanks for the reply. I tried initially to include the desired output document but it would not upload. I wasn't sure what the problem was. But I've managed to upload it in this message.



Thank you :yes

fumei
03-23-2014, 07:34 PM
Where is the textbox, and why do you want to use a textbox anyway.

macropod
03-24-2014, 12:18 AM
Even more to the point, mbbx5va2, why aren't you using a template as the basis of your document, instead of trying to brute-force the layout in code?

mbbx5va2
03-24-2014, 11:13 AM
Hi thanks for the reply.

The text box is beneath the payee name on the 'Letterformat' attachment. In addition to this document I will be writing letters to clients and will be using a couple of text boxes to put the client and company addresses in.

The entire process involves clicking a macro button on a spreadsheet which extracts data from the sheet and puts it into selected places in multiple letters. I've created the correct code to produce to extract the right data but the output is not arranged how I want. So the code that needs amending is the one above.

caruggles
03-24-2014, 02:27 PM
Hi, mbbx5va2.


It sounds more like you would want to do a mail merge in Word. Why are you opting to do the mail merge via Excel into Word instead? Your Excel file would be your data source and it would just require setting up the document once and then you would run the mail merge in Word each time you updated the data set. It sounds like you are taking a lot of extra effort to do it via Excel when it would be faster to do it via Word.


Can you provide more information as to why what you are trying to accomplish with Excel would not be accomplished using a mail merge in Word? I'm unsure of what to suggest since my primary suggestion would be to create a template (like Macropod suggested) and do a Word mail merge with your Excel file.

fumei
03-25-2014, 12:26 AM
It definitely sounds like it could be a mail merge. Also, it seems that textbox means a TABLE. The main point was asked by macropod...why on earth would you brute force build a layout when you could use a template.

mbbx5va2
03-25-2014, 11:50 AM
Hi many thanks for the replies.

Yes I think you are all right. I should have just used a mail merge - which I did after reading your post caruggles. For some reason nobody at work is using it. As for the text box - I won't be needing that as I can just put fields for address lines using the mail merge. :yay

fumei
03-25-2014, 02:07 PM
And there you go. Oh, and it was never a textbox, at least in the document you attached. It was a table.