Results 1 to 8 of 8

Thread: [RESOLVED] Aligning Text in MS Word Thru VB6

  1. #1

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    40

    Resolved [RESOLVED] Aligning Text in MS Word Thru VB6

    Is There A Way On How To Align Text (ie. center) From MS Word Thru VB6 Code? I didnt used a table. is it still possible? A good code would be much appreciated... Thanks

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Aligning Text in MS Word Thru VB6

    I don't understand the question. You want to center-align text in a Word document? Can't you just record a macro to do that and then look at the recorded macro's VBA code?

  3. #3

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    40

    Re: Aligning Text in MS Word Thru VB6

    I have here these sample codes:

    ------------------------------------------------
    Dim oApp As Word.Application
    Dim oDoc As Word.Document
    Set oApp = New Word.Application

    'Open either a blank new document or...
    Set oDoc = oApp.Documents.Add

    'open an exisiting document
    'Set oDoc = oApp.Documents.Open("C:\Document1.doc")
    oDoc.Activate

    With oApp.Selection
    'Move to the last line and add a new line.
    .GoTo What:=wdGoToLine, Which:=wdGoToLast
    .TypeParagraph

    .Font.Size = 10
    .Font.Name = "Arial"
    .TypeText Text:="Sample Text"
    End With
    oApp.Visible = True

    Set oDoc = Nothing
    Set oApp = Nothing

    ------------------------------------------------

    How will i align to center that text?

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Aligning Text in MS Word Thru VB6

    If you would be using the macro-recorder, you would get something like.
    Code:
    'the text you want to center has to be selected!
        Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    But you can't do that, since you are busy from double/tripple/quadruple psting the same question!

    BTW: I won't post an answer to your other threat!

    Note: Double-posting is considered to be bad manners!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Aligning Text in MS Word Thru VB6

    I am only online for a minute but I see you got the code from my FAQ. You have uncommented both methods of opening/creating a document.

    If you already have the doc to open the dont create a new one.

    Do like suggested and record a macro whenever you want to know how its done in Word.

    http://vbforums.com/showthread.php?t=402032

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    40

    Re: Aligning Text in MS Word Thru VB6

    RobDog888,

    Im so sorry for all of that.. Im already confused of what to do with this. I've decided to bring out a clear case for you to help me.
    This is a sample problem;
    Suppose i have to put up a header on Word consisting of an image to the left and text on the center, like what common header have. Say,



    !----------!..............Republic Of The Country
    !->image<-!...................Province Of Prov
    !----------!..................Cty Of Downtown


    ...Just like that
    Can you pls make me a VB code for this with the output in MS Word? This will help me alot Mr. RobDog888. Hope you'll grant me with this one.

    Thanks alot!!! More Power to You!!!

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Aligning Text in MS Word Thru VB6

    Quote Originally Posted by Ellis Dee
    I don't understand the question. You want to center-align text in a Word document? Can't you just record a macro to do that and then look at the recorded macro's VBA code?
    Did you try this approach?

    Recording a macro and using the resulting code in VB6 has always worked for me.

  8. #8

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    40

    Re: Aligning Text in MS Word Thru VB6

    RobDog888 and Hack, first of all, i don't know in the first place on what to do with what you're sayin' bout that macro. 2nd, that docs will be created through VB Code on which variables from VB should be put to MS Word...

    Hope you got what i'm saying, help me...

    Thanks alot!!!

Posting Permissions

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



Click Here to Expand Forum to Full Width