Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

MS Word + enumeration

Hi!

HOw can i use a the "enumaration"(the circel) of Word in my VB Programme? (if i have already started Word, see below)


...
on error resume next
Dim WordApp as Object

Set WordApp = GetObject(, "Word.Application")
if err.number<>0 then
    set Wordapp = CreateObject("Word.Application")
endif

with Wordapp
  wordapp.documents.add
  'Font bold
  wordapp.selection.font.bold=true
  wordapp.selection.selection.typetext Text:="Test"
end with

...
0
Falk2
Asked:
Falk2
  • 5
  • 4
  • 3
  • +2
1 Solution
 
bruintjeCommented:
Hi Falk2, the best source for the properties, methods etc in the MS Word object model is the VBA Editor in Word,

- you can pop this up with ALT+F11 in Word
- then use F2 to get the property explorer

and of course on the net
http://www.vbsquare.com/api/wordobj1/
http://www.vbsquare.com/api/wordobj2/

and the OPG
http://www.microsoft.com/officedev/articles/Opg/007/007.htm

HTH:O)Bruintje
0
 
Falk2Author Commented:
i only want to add a list with "dots"

like:

* List1
* List2
* List3

to difficult to add ?

Falke
0
 
bruintjeCommented:
try

Sub Make_List()
  With Application
    .Selection.HomeKey unit:=wdLine
    .Selection.MoveUp unit:=wdLine, Count:=3
    .Selection.MoveDown unit:=wdLine, Count:=3, Extend:=wdExtend
    With .ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
      .NumberFormat = ChrW(61623)
      .TrailingCharacter = wdTrailingTab
      .NumberStyle = wdListNumberStyleBullet
      .NumberPosition = InchesToPoints(0)
      .Alignment = wdListLevelAlignLeft
      .TextPosition = InchesToPoints(0.25)
      .TabPosition = InchesToPoints(0.25)
      .ResetOnHigher = True
      .StartAt = 1
      With .Font
        .Bold = wdUndefined
        .Italic = wdUndefined
        .StrikeThrough = wdUndefined
        .Subscript = wdUndefined
        .Superscript = wdUndefined
        .Shadow = wdUndefined
        .Outline = wdUndefined
        .Emboss = wdUndefined
        .Engrave = wdUndefined
        .AllCaps = wdUndefined
        .Hidden = wdUndefined
        .Underline = wdUndefined
        .ColorIndex = wdUndefined
        .Size = wdUndefined
        .Animation = wdUndefined
        .DoubleStrikeThrough = wdUndefined
        .Name = "Symbol"
      End With
      .LinkedStyle = ""
    End With
    .ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
    .Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
      wdBulletGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
      wdListApplyToWholeList
  End With
End Sub

HTH:O)Bruintje
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Falk2Author Commented:
that's a macro in Word ;)

but if you tried to do this in Visual Basic and start it as i do it, some errors are "approaching" ;)

try it out ...

Falke
0
 
bruintjeCommented:
then try

Private Sub Command1_Click()
Dim WordApp As Object

Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
   Set WordApp = CreateObject("Word.Application")
End If

WordApp.Visible = True

With WordApp
   .Documents.Add
   .Selection.HomeKey unit:=wdLine
   .Selection.MoveUp unit:=wdLine, Count:=3
   .Selection.MoveDown unit:=wdLine, Count:=3, Extend:=wdExtend
   With .ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
     .NumberFormat = ChrW(61623)
     .TrailingCharacter = wdTrailingTab
     .NumberStyle = wdListNumberStyleBullet
     .NumberPosition = InchesToPoints(0)
     .Alignment = wdListLevelAlignLeft
     .TextPosition = InchesToPoints(0.25)
     .TabPosition = InchesToPoints(0.25)
     .ResetOnHigher = True
     .StartAt = 1
     With .Font
       .Bold = wdUndefined
       .Italic = wdUndefined
       .Strikethrough = wdUndefined
       .Subscript = wdUndefined
       .Superscript = wdUndefined
       .Shadow = wdUndefined
       .Outline = wdUndefined
       .Emboss = wdUndefined
       .Engrave = wdUndefined
       .AllCaps = wdUndefined
       .Hidden = wdUndefined
       .Underline = wdUndefined
       .ColorIndex = wdUndefined
       .Size = wdUndefined
       .Animation = wdUndefined
       .DoubleStrikeThrough = wdUndefined
       .Name = "Symbol"
     End With
     .LinkedStyle = ""
   End With
   .ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
   .Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
     wdBulletGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
     wdListApplyToWholeList
 End With

End Sub

all right i forgot to tell that the code could simply be pasted in vb

HTH:O)Bruintje
0
 
Falk2Author Commented:
i have modified it that in works in VISUAL Basic:

Private Sub Command1_Click()
Dim WordApp As Object

Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
  Set WordApp = CreateObject("Word.Application")
End If

WordApp.Visible = True

With WordApp
  .Documents.Add
  .Selection.HomeKey unit:=.wdLine
  .Selection.MoveUp unit:=.wdLine, Count:=3
  .Selection.MoveDown unit:=.wdLine, Count:=3, Extend:=.wdExtend
  With .ListGalleries(.wdBulletGallery).ListTemplates(1).ListLevels(1)
    .NumberFormat = ChrW(61623)
    .TrailingCharacter = .wdTrailingTab
    .NumberStyle = .wdListNumberStyleBullet
    .NumberPosition = .InchesToPoints(0)
    .Alignment = .wdListLevelAlignLeft
    .TextPosition = .InchesToPoints(0.25)
    .TabPosition = .InchesToPoints(0.25)
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
      .Bold = .wdUndefined
      .Italic = .wdUndefined
      .Strikethrough = .wdUndefined
      .Subscript = .wdUndefined
      .Superscript = .wdUndefined
      .Shadow = .wdUndefined
      .Outline = .wdUndefined
      .Emboss = .wdUndefined
      .Engrave = .wdUndefined
      .AllCaps = .wdUndefined
      .Hidden = .wdUndefined
      .Underline = .wdUndefined
      .ColorIndex = .wdUndefined
      .Size = .wdUndefined
      .Animation = .wdUndefined
      .DoubleStrikeThrough = .wdUndefined
      .Name = "Symbol"
    End With
    .LinkedStyle = ""
  End With
  .ListGalleries(.wdBulletGallery).ListTemplates(1).Name = ""
  .Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=.ListGalleries( _
    .wdBulletGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
    .wdListApplyToWholeList
End With

End Sub


but if i try it i got an error in line:

.Selection.HomeKey unit:=.wdLine

(438 object does not support this argument (or so - translated in english))

Falke
0
 
bruintjeCommented:
what these lines do

go back to the beginning of the line
 .Selection.HomeKey unit:=.wdLine
still selecting go up unit=line count=3 so 3 lines up
 .Selection.MoveUp unit:=.wdLine, Count:=3

still selecting go down unit=line count=3 so 3 lines down
 .Selection.MoveDown unit:=.wdLine, Count:=3, Extend:=.wdExtend

all right it's bit forced to select a block of 3 lines like this but it works here,

which version of vb/word do you have there?

:O)Bruintje
0
 
ZimmyCommented:
Since you are adding a new (empty) document,You could simply add 3 paragraphs to the current selection by writing:

Selection.Text = vbCrLf & vbCrLf & vbCrlf

When that line runs, the selection will include all three paragraphs you just created.
Then you can apply formatting by identifying a Word style that has the bullet format you desire. For Instance, Word typically comes with a built-in style called "List Bullet", which can be applied to a Range object as below:

Selection.Range.Style = "List Bullet"

So, to create
* List1
* List2
* List3

I would suggest something like:

Documents.Add
For n = 1 To 3
Selection.Text = "List" & n & vbCrLf
Selection.Range.Style = "List Bullet"
Selection.Collapse Direction:=wdCollapseEnd
Next n

Be sure that the style you specify is the exact name of a style you are confident will be available to the document you add. (e.g. a style in your Normal.dot)

I hope this helps,
~Zimmy
0
 
Falk2Author Commented:
>which version of vb/word do you have there?

i use VB 6.0 and Word 97.

>.g. a style in your Normal.dot
how can i create automatically a style? Or if this doesn't work how can i save this style i have made in NORMAL.DOT?

Falke
0
 
ZimmyCommented:
To save a style you create in Normal.dot, just open a blank document and click Format->Style->New.
Fill in the name and all of the formatting specifics, click Add To Template. This should save the style in your Normal template.
To create a style programmatically, you could do something like this:

Sub stylecreate()
ActiveDocument.Styles.Add "myNewStyle1", wdParagraph
With ActiveDocument.Styles("myNewStyle1")
   .ParagraphFormat.Alignment = wdAlignParagraphJustify
   'add as many formats as you want
   'record them with the macro recorder to get the
   'names
End With
End Sub
0
 
Falk2Author Commented:
error 5843 ;) in line

ActiveDocument.Styles.Add "myNewStyle1", wdParagraph
0
 
ZimmyCommented:
My apologies for not entering the accurate type enumeration. The following should do the trick.
For the possible style types, refer to "Add Method (Styles Collection)" in the Word VBA help

Sub stylecreate()
ActiveDocument.Styles.Add Name:="myNewStyle2", Type:=wdStyleTypeParagraph
With ActiveDocument.Styles("myNewStyle2")
  .ParagraphFormat.Alignment = wdAlignParagraphJustify
  'add as many formats as you want
  'record them with the macro recorder to get the
  'names
End With
End Sub
0
 
DanRollinsCommented:
Hi Falk2,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Zimmy's comment(s) as an answer.

Falk2, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
NetminderCommented:
Per recommendation, force-accepted.

Netminder
CS Moderator
0
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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