Solved

MS Word + enumeration

Posted on 2001-09-09
14
422 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now