• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Automating Word

Okey using word is easy and automating is also a sinch,

but im so stuck on formatting.

how the hell do i do this simple task

TITLE, needs to be in middle at top of screen

rest of the body needs to be left justified and starting on a new line,

example of some of my code im using

Dim wdApp As Word.Application
    Dim myDoc As Word.Document
    Dim mywdRange As Word.Range

   With wdApp
            .Visible = True
             .WindowState = wdWindowStateMaximize
            End With

            Set myDoc = wdApp.Documents.Add
            Set mywdRange = myDoc.Words(1)
            With mywdRange
            'create title in word
            .Text = " Blue Print Rail - Project Management Database" & vbCrLf
            .Font.name = "Arial"
            .Font.Size = 14
            .Font.ColorIndex = wdBlack
            .Bold = True

  • 4
  • 2
  • 2
  • +2
1 Solution
The easiest way to perform this is to go into word, type out the sentence then goto tools macro / record new macro.  Once you have recorded the macro, simply edit and copy the text, and paste it into your automation code.


last message was incomplete, should have read

The easiest way to perform this is to go into word, type out the sentence then goto tools macro / record
new macro.

Now format the text as you wish. when you are happy with the result, stop recording.

Now simply edit the macro copy the text, and paste it into your automation code.
andysalihAuthor Commented:
I would rather be able just to open word and create the document by passing text through code.

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Hi Andysalih,

Maybe a bit overkill(in lenght)


but it contains a lot of good pointers and a suggestion that addresses your problem

With Selection.Font
         .Size = 14
         .Bold = True
End With

  The following is an example of formatting paragraphs:

With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 0
        .SpaceAfter = 0
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
End With


have you thought of using a template?  Create a new template then create a style (DocTitle) that is formatted to your contentment (ensure that the style for "followin paragraph" is set to "Normal") then all you have to do is:

set objWord = new word.application
set wrdDoc = objWord.documents.add(strTemplate)

set wrdRange = wrdDoc.words(1)
wrdRange.style = "DocTitle"
wrdRange.text = "Blah blah blah"

.... etc
Note the use of "insertparagraphafter"; if you use VBCRLF in your code, word sees it as a soft return and does not change the style.

BTW your code will run more quickly if you keep objword invisible until the end.

wow you've got a lot of open Q's

and since i'm also cleaning up Access i'm interested if you plan on closing a few down sometime? 6 out of 6.

and if we gonna see you back here?

just a random thought

btw if you got no answer on a question you can ask a 0-point Q in community support to refund the points and make it a PAQ or delete the question

You have 14 open questions today, all of which need your attention.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
POINTS FOR EXPERTS awaiting comments are listed in the link below
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moderator @ Experts Exchange
thanks for the grade but why a B?
Please do let us know why a "B" vs an "A", it not only helps us understand any shortfalls, but also those who access this item in the future from our PAQ.  If this was done in error, I can correct it.
Moondancer - EE Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now