2012-05-01 17 views
7

Estoy tratando de reemplazar las balas de una lista en un documento de Word con guiones, básicamente, sólo el icono "traducida" se va a sustituir, es decirReemplazar las balas con guiones en un documento de Word

Reemplazar las balas de la a continuación la lista:

  • este es un elemento de la lista

  • este es otro elemento de la lista

  • otro elemento

con guiones:

- Este es un elemento de la lista

- este es otro elemento de la lista

- otro elemento

Voy a hacer esto usando ActiveX en Delphi, pero el código VB también lo haría, ¡gracias!

Respuesta

5

Dentro Delphi código:

uses ..., ComObj; 

const 
    wdListNumberStyleBullet = 23; 
var 
    vMSWord      : variant; 
    Doc       : Variant; 
    oListTemplate    : Variant; 
    oListLevel     : Variant; 
    iLoopTemplates, iMaxTemplates: Integer; 
    iLoopLevels, iMaxLevels  : Integer; 
begin 
    try 
    vMSWord   := GetActiveOleObject('Word.Application'); 
    vMSWord.Visible := True; 
    Doc    := vMSWord.ActiveDocument; 
    iMaxTemplates := Doc.ListTemplates.Count; 
    for iLoopTemplates := 1 to iMaxTemplates do 
    begin 
     oListTemplate := Doc.ListTemplates.Item(iLoopTemplates); 
     iMaxLevels := oListTemplate.ListLevels.Count; 
     for iLoopLevels := 1 to iMaxLevels do 
     begin 
     oListLevel := oListTemplate.ListLevels.Item(iLoopLevels); 
     if  (oListLevel.NumberStyle = wdListNumberStyleBullet) 
      and (oListLevel.NumberFormat = UTF8String(#61623)) 
      and (oListLevel.Font.Name = 'Symbol') then 
//  if (oListLevel.NumberStyle = wdListNumberStyleBullet) then 
     begin 
      oListLevel.NumberFormat := UTF8String('-'); 
      oListLevel.Font.Name := 'Arial'; 
     end; 
     end; 
    end; 
    except 
    ShowMessage('Open a Word document before running this method'); 
    end; 

La corriente SI es comprobar si es realmente una bala • facturan con un •

Si no necesita esta comprobación, comentar esta línea (si ...) y elimine la siguiente ...

+0

+1 muchas gracias, todavía no lo busqué, pero si su código funciona ¡de fábrica, lo aceptaré como respuesta! (: – ComputerSaysNo

+0

Lo he probado con Delphi XE2 y Word 2010 ... así que, esto debería funcionar para usted también ...; o) – Whiler

+0

gracias por el esfuerzo extra para proporcionar el código Delphi, he aceptado su respuesta debido al esfuerzo extra. – ComputerSaysNo

6

¿Esto es lo que estás intentando?

Option Explicit 

'~~> Select the relevant range before running this code 
Sub Sample() 
    With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1) 
     .NumberFormat = ChrW(61485) 
     .TrailingCharacter = wdTrailingTab 
     .NumberStyle = wdListNumberStyleBullet 
     .NumberPosition = InchesToPoints(0.25) 
     .Alignment = wdListLevelAlignLeft 
     .TextPosition = InchesToPoints(0.5) 
     .ResetOnHigher = 0 
     .StartAt = 1 
     .Font.Name = "Symbol" 
     .LinkedStyle = "" 
    End With 
    ListGalleries(wdBulletGallery).ListTemplates(1).Name = "" 

    Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _ 
    ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _ 
    False, ApplyTo:=wdListApplyToSelection, DefaultListBehavior:= _ 
    wdWord10ListBehavior 
End Sub 

INSTANTÁNEA

enter image description here

+0

+1 y aceptado, muchas gracias señor! – ComputerSaysNo

+0

+1 muy bien codificado. – brettdj

4

Una macro, que hace el trabajo ...

Dim oListTemplate As ListTemplate 
Dim oListLevel As ListLevel 

For Each oListTemplate In ActiveDocument.ListTemplates 
    For Each oListLevel In oListTemplate.ListLevels 
     If oListLevel.NumberStyle = wdListNumberStyleBullet Then 
      With oListLevel 
       .NumberFormat = "-" 
       .Font.Name = "Arial" 
      End With 
     End If 
    Next oListLevel 
Next oListTemplate 
+0

Creo que esta es una solución mucho mejor y mucho más robusta. El primero parece ser el resultado de grabar una macro y no funcionará en múltiples listas o máquinas con un conjunto diferente de plantillas de lista. – Alain

+0

+1 gracias por la respuesta – ComputerSaysNo

+1

@DorinDuminica: No sé si necesita * solo * reemplazar las * viñetas * con guiones ... en caso afirmativo, debe agregar una segunda prueba para verificar si el carácter actual es: .NumberFormat = ChrW (61623) AND .Font.Name = "Símbolo" – Whiler

Cuestiones relacionadas