Solved

MS Word + enumeration

Posted on 2001-09-09
14
432 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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 50 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
message box in access 4 51
vb6 connector to mongodb 2 117
How to produce a SHA-1 hash function in vb6 in order to save it to a table 8 51
Excel Automation VBA 19 88
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 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