Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2013, 11:24 PM
macropod's Avatar
macropod macropod is offline Bulletted List Creation Windows 7 32bit Bulletted List Creation Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,379
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default


Try something based on:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Stl As Style, bBulletA As Boolean, bBulletB As Boolean
bBulletA = False: bBulletB = False
For Each Stl In ActiveDocument.Styles
  If Stl.NameLocal = "BulletA" Then bBulletA = True
  If Stl.NameLocal = "BulletB" Then bBulletB = True
Next
If bBulletA = False Then Call AddBulletStyle("BulletA", ChrW(61623), InchesToPoints(0), InchesToPoints(0.5), True)
If bBulletB = False Then Call AddBulletStyle("BulletB", "o", InchesToPoints(1), InchesToPoints(1.5), False)
With ActiveDocument.Range
  .Style = "BulletA"
  .Paragraphs.First.Style = "Normal"
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^13Exceeded[!^13]@^13"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    .Start = .Start + 1
    .End = .End - 1
    .Style = "BulletB"
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
 
Private Sub AddBulletStyle(StrNm As String, StrBullet As String, iIndnt As Single, iHang As Single, bFntBld As Boolean)
Dim Stl As Style
Set Stl = ActiveDocument.Styles.Add(Name:=StrNm, Type:=wdStyleTypeParagraph)
With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
  .NumberFormat = StrBullet
  .TrailingCharacter = wdTrailingTab
  .NumberStyle = wdListNumberStyleBullet
  .NumberPosition = InchesToPoints(0)
  .Alignment = wdListLevelAlignLeft
  .ResetOnHigher = 0
  .StartAt = 1
  .LinkedStyle = StrNm
End With
With Stl
  .AutomaticallyUpdate = False
  .BaseStyle = "Normal"
  .LinkToListTemplate _
    ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(1), ListLevelNumber:=1
  With .ParagraphFormat
    .LeftIndent = iHang
    .RightIndent = InchesToPoints(0)
    .FirstLineIndent = -iHang + iIndnt
    .TabStops.ClearAll
    .TabStops.Add Position:=iHang, _
      Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
  End With
  .Font.Bold = bFntBld
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 11-11-2013, 07:20 AM
jdean jdean is offline Bulletted List Creation Windows XP Bulletted List Creation Office 2010 32bit
Novice
Bulletted List Creation
 
Join Date: Nov 2013
Posts: 14
jdean is on a distinguished road
Default

Macropod,

I tested the code several times. Each time, it seems to work the first time, but when I run it again, I get: Run-Time Error '462': The remote server machine does not exist or is unavailable.

This is how I have my code set up from an Excel activeX control:
Code:
'== I placed Sub AddBullet () in the "General Section" of the Module. The only change I made there was change Stl As Style to Stl As Word.Style

'== Followed by my code:
Sub Mycode()
 t=Worksheets(1).Range("A3:A10000").SpecialCells(xlCellTypeConstants).Cells.Count
    Set a = Worksheets(1).Range("A5").Cells
    Set b = Worksheets(1).Range("B5").Cells
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Dim strFirstWord As String
    Dim oPara As Word.Paragraph
    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
    Set wrdDoc = wrdApp.Documents.Add

    Application.ScreenUpdating = false
    wrdApp.WindowState = wdWindowStateMinimize

    With wrdApp.Selection
       .TypeText Text:="Drafted" &  Something
       .TypeParagraph
        For i = 1 To t
            .ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
            .ParagraphFormat.LineSpacing = 10
            .TypeText Text:=a.Value
            .TypeParagraph
            .TypeText Text:=b.Value
            .TypeParagraph
            Set a = a.Offset(1, 0).Cells
            Set b = b.Offset(1, 0).Cells
        Next i
     End With
    
    
     For Each oPara In wrdDoc.Paragraphs
        strFirstWord = oPara.Range.Words(1).Text
        With oPara.Range.Font
             .Name = "Tahoma"
             .Size = 10
        End With
        If Trim(strFirstWord) = "Drafted" Then
           oPara.Range.Font.Bold = True
        ElseIf Trim(strFirstWord) <> "Drafted" And Trim(strFirstWord) <> "Exceeded" Then
           oPara.Range.Font.Bold = True
           oPara.SpaceAfter = 0 
        ElseIf Trim(strFirstWord) = "Exceeded" Then
           For i = 2 To 20
               oPara.Range.Characters(i).Font.Italic = True
           Next i
        End If
    Next

'== Followed by Demo()  WIITHIN MyCode entered as
    Dim Stl As Word.Style, bBulletA As Boolean, bBulletB As Boolean
    bBulletA = False: bBulletB = False
    For Each Stl In wrdDoc.Styles
      If Stl.NameLocal = "BulletA" Then bBulletA = True
      If Stl.NameLocal = "BulletB" Then bBulletB = True
    Next
    If bBulletA = False Then Call AddBulletStyle("BulletA", ChrW(61623), InchesToPoints(0), InchesToPoints(0.5), True)
    If bBulletB = False Then Call AddBulletStyle("BulletB", "o", InchesToPoints(1), InchesToPoints(1.5), False)
    With wrdDoc.Range
      .Style = "BulletA"
      .Paragraphs.First.Style = "Normal"
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "^13Exceeded[!^13]@^13"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchWildcards = True
        .Execute
      End With
      Do While .Find.Found
        .Start = .Start + 1
        .End = .End - 1
        .Style = "BulletB"
        .Collapse wdCollapseEnd
        .Find.Execute
      Loop
    End With

'== Followed by

    wrdApp.WindowState = wdWindowStateNormal
    Set wrdApp = Nothing
    Set wrdDoc = Nothing
     Application.ScreenUpdating = True
end sub
Thanks!
Jay

Last edited by jdean; 11-11-2013 at 07:25 AM. Reason: correction
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calendar Creation sjvjoe Publisher 1 07-14-2016 06:32 PM
Bulletted List Creation Document Creation Privateer Word 3 06-20-2013 08:15 PM
Help with Complex Table Creation saquib Word 0 02-12-2013 06:28 AM
Bulletted List Creation Label Creation speloquin Word 1 05-27-2011 03:08 PM
Report creation. Igtech Excel 1 04-02-2010 03:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:22 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft