Solved

Automating Word

Posted on 2002-04-15
10
261 Views
Last Modified: 2008-02-01
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
               

0
Comment
Question by:andysalih
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 2

Expert Comment

by:kiddiec
ID: 6941986
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.

0
 
LVL 2

Expert Comment

by:kiddiec
ID: 6941993
Sorry,

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.
0
 
LVL 3

Author Comment

by:andysalih
ID: 6942091
I would rather be able just to open word and create the document by passing text through code.

cheers
0
Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

 
LVL 44

Accepted Solution

by:
bruintje earned 200 total points
ID: 6942678
Hi Andysalih,

Maybe a bit overkill(in lenght)

http://www.microsoft.com/worddev/articles/movs201.htm

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
 

HTH:O)Bruintje
0
 
LVL 10

Expert Comment

by:RichardCorrie
ID: 6948322
Andysalih

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"
wrdRange.insertparagraphafter

.... 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.

Richard
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6948340
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

:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6948345
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

:O)Bruintje
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7018895
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.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
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.
http://www.experts-exchange.com/questions/Q.20162276.html
http://www.experts-exchange.com/questions/Q.20173360.html
http://www.experts-exchange.com/questions/Q.20188764.html
http://www.experts-exchange.com/questions/Q.20192160.html
http://www.experts-exchange.com/questions/Q.20194450.html
http://www.experts-exchange.com/questions/Q.20227206.html
http://www.experts-exchange.com/questions/Q.20250618.html
http://www.experts-exchange.com/questions/Q.20281960.html
http://www.experts-exchange.com/questions/Q.20281976.html
http://www.experts-exchange.com/questions/Q.20287352.html
http://www.experts-exchange.com/questions/Q.20289484.html
http://www.experts-exchange.com/questions/Q.20289520.html
http://www.experts-exchange.com/questions/Q.20295341.html
http://www.experts-exchange.com/questions/Q.20301680.html



*****  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
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
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.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7037000
thanks for the grade but why a B?
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7037639
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.
Thanks,
Moondancer - EE Moderator
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question