Consulting

Results 1 to 10 of 10

Thread: want specific output in word but in terms of vba code

  1. #1
    VBAX Regular
    Joined
    Feb 2013
    Posts
    51
    Location

    want specific output in word but in terms of vba code

    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?
    Attached Files Attached Files

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    The attached document is not helpful. What would be helpful is a document showing what you want it to look like.

  3. #3
    VBAX Regular
    Joined
    Feb 2013
    Posts
    51
    Location
    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
    Attached Files Attached Files

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Where is the textbox, and why do you want to use a textbox anyway.

  5. #5
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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?
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    VBAX Regular
    Joined
    Feb 2013
    Posts
    51
    Location
    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.

  7. #7
    VBAX Newbie
    Joined
    Mar 2014
    Location
    Seattle, WA
    Posts
    1
    Location
    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.
    Cat
    (MOS Master Level - Word 2007, Excel 2007, PowerPoint 2007, Outlook 2007, Access 2007)

  8. #8
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

  9. #9
    VBAX Regular
    Joined
    Feb 2013
    Posts
    51
    Location
    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.

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    And there you go. Oh, and it was never a textbox, at least in the document you attached. It was a table.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •