Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS Word + enumeration

Posted on 2001-09-09
14
Medium Priority
?
462 Views
Last Modified: 2012-08-14
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
Comment
Question by:Falk2
  • 5
  • 4
  • 3
  • +2
14 Comments
 
LVL 44

Expert Comment

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

Author Comment

by:Falk2
ID: 6469896
i only want to add a list with "dots"

like:

* List1
* List2
* List3

to difficult to add ?

Falke
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6469942
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Falk2
ID: 6470252
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
 
LVL 44

Expert Comment

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

Author Comment

by:Falk2
ID: 6471766
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
 
LVL 44

Expert Comment

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

Accepted Solution

by:
Zimmy earned 200 total points
ID: 6473217
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
 

Author Comment

by:Falk2
ID: 6473641
>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
 

Expert Comment

by:Zimmy
ID: 6492368
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
 

Author Comment

by:Falk2
ID: 6492869
error 5843 ;) in line

ActiveDocument.Styles.Add "myNewStyle1", wdParagraph
0
 

Expert Comment

by:Zimmy
ID: 6497115
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7207772
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
 
LVL 5

Expert Comment

by:Netminder
ID: 7241104
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

963 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