Solved

Automating Word

Posted on 2002-04-15
10
254 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now