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 :)
Printable View
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 :)
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?
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?
If you would be using the macro-recorder, you would get something like.
But you can't do that, since you are busy from double/tripple/quadruple psting the same question!Code:'the text you want to center has to be selected!
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
BTW: I won't post an answer to your other threat!
Note: Double-posting is considered to be bad manners!
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
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!!!
Did you try this approach?Quote:
Originally Posted by Ellis Dee
Recording a macro and using the resulting code in VB6 has always worked for me.
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!!!