0
我遇到了麻煩,不知道爲什麼。我有一個過程來創建一些樣式,其中一些與鏈接列表模板。我在normal.dotm模板裏面有這個模塊(工作內容)。我第一次執行它,它工作正常,並創建了所有樣式,包括鏈接到列表。但在此之後,當我打開單詞時,鏈接到列表樣式顯示爲未鏈接,如果我再次執行該過程,則會創建它們不鏈接。任何想法?在此先感謝vba word linktolisttemplate無法正常工作
這裏的代碼,CrearEstilos先刪除所有quickstyles和創建的,然後重新創建,使他們quickstyles
Dim aux As Integer
Sub CrearEstilos()
BorrarEstilos
Estilos
EstilosRapidos
End Sub
Private Sub Estilos()
'Procedimiento para crear los estilos en caso necesario
Dim t1 As Style, t2 As Style, t3 As Style, t4 As Style, pregunta As Style, respuesta As Style, recuer As Style, inde As Style
'Titulo nivel 1
If existe("Titulo nivel 1") = False Then
Set t1 = ActiveDocument.Styles.Add(Name:="Titulo nivel 1", _
Type:=WdStyleType.wdStyleTypeParagraph)
With t1
.Font.Bold = False
.Font.Italic = False
.Font.Name = "Verdana"
.Font.Size = 36
.ParagraphFormat.OutlineLevel = wdOutlineLevel1
.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
.ParagraphFormat.LineSpacing = LinesToPoints(1)
End With
End If
'Titulo nivel 2
If existe("Titulo nivel 2") = False Then
Set t2 = ActiveDocument.Styles.Add(Name:="Titulo nivel 2", _
Type:=WdStyleType.wdStyleTypeParagraph)
With t2
.Font.Bold = True
.Font.Italic = False
.Font.Name = "Verdana"
.Font.Size = 16
.ParagraphFormat.OutlineLevel = wdOutlineLevel2
.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
.ParagraphFormat.LineSpacing = LinesToPoints(1)
End With
End If
'Titulo nivel 3
If existe("Titulo nivel 3") = False Then
Set t3 = ActiveDocument.Styles.Add(Name:="Titulo nivel 3", _
Type:=WdStyleType.wdStyleTypeParagraph)
With t3
.Font.Bold = True
.Font.Italic = False
.Font.Name = "Verdana"
.Font.Size = 14
.ParagraphFormat.OutlineLevel = wdOutlineLevel3
.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
.ParagraphFormat.LineSpacing = LinesToPoints(1)
End With
End If
'Titulo nivel 4
If existe("Titulo nivel 4") = False Then
Set t4 = ActiveDocument.Styles.Add(Name:="Titulo nivel 4", _
Type:=WdStyleType.wdStyleTypeParagraph)
With t4
.Font.Bold = True
.Font.Italic = False
.Font.Name = "Verdana"
.Font.Size = 12
.ParagraphFormat.OutlineLevel = wdOutlineLevel4
.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
.ParagraphFormat.LineSpacing = LinesToPoints(1)
End With
End If
'Titulo independiente
If existe("Titulo independiente") = False Then
Set t4 = ActiveDocument.Styles.Add(Name:="Titulo independiente", _
Type:=WdStyleType.wdStyleTypeParagraph)
With t4
.Font.Bold = True
.Font.Italic = True
.Font.Name = "Verdana"
.Font.Size = 11
.ParagraphFormat.OutlineLevel = 10
.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
.ParagraphFormat.LineSpacing = LinesToPoints(1)
End With
End If
'Preguntas
If existe("Preguntas autoevaluacion") = False Then
Set pregunta = ActiveDocument.Styles.Add(Name:="Preguntas autoevaluacion", _
Type:=WdStyleType.wdStyleTypeParagraph)
With pregunta
.Font.Bold = True
.Font.Italic = False
.Font.Name = "Verdana"
.Font.Size = 10
.ParagraphFormat.OutlineLevel = 10
.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
.ParagraphFormat.LineSpacing = LinesToPoints(1)
End With
End If
'Respuestas
If existe("Respuestas autoevaluacion") = False Then
Set respuesta = ActiveDocument.Styles.Add(Name:="Respuestas autoevaluacion", _
Type:=WdStyleType.wdStyleTypeParagraph)
With respuesta
.Font.Bold = False
.Font.Italic = False
.Font.Name = "Verdana"
.Font.Size = 10
.ParagraphFormat.OutlineLevel = 10
.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
.ParagraphFormat.LineSpacing = LinesToPoints(1)
.LinkToListTemplate ListTemplate:=ListGalleries(wdNumberGallery).ListTemplates(5), _
ListLevelNumber:=1
End With
End If
'Recuerdas
If existe("Recuerdas unidad") = False Then
Set recuer = ActiveDocument.Styles.Add(Name:="Recuerdas unidad", _
Type:=WdStyleType.wdStyleTypeParagraph)
With recuer
.Font.Bold = False
.Font.Italic = False
.Font.Name = "Verdana"
.Font.Size = 10
.ParagraphFormat.OutlineLevel = 10
.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
.ParagraphFormat.LineSpacing = LinesToPoints(1)
.LinkToListTemplate ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(1), _
ListLevelNumber:=1
End With
End If
ActiveDocument.UpdateStyles
End Sub
Private Sub EstilosRapidos()
'Establece los estilos rápidos
Dim s As Style
'Primero borramos la lista
For Each s In ActiveDocument.Styles
If s.Type = wdStyleTypeCharacter Or _
s.Type = wdStyleTypeParagraph Or _
s.Type = wdStyleTypeLinked Then
s.QuickStyle = False
End If
Next s
'Creamos los estilos
'Estilos
'Marcamos como rápidos los necesarios
For Each s In ActiveDocument.Styles
If s.NameLocal = "Titulo nivel 1" Or s.NameLocal = "Titulo nivel 2" Or s.NameLocal = "Titulo nivel 3" Or _
s.NameLocal = "Titulo nivel 4" Or s.NameLocal = "Preguntas autoevaluacion" Or s.NameLocal = "Respuestas autoevaluacion" Or _
s.NameLocal = "Recuerdas unidad" Or s.NameLocal = "Normal" Or s.NameLocal = "Titulo independiente" Then
s.QuickStyle = True
End If
Next s
End Sub
Private Sub BorrarEstilos()
'Establece los estilos rápidos
Dim r As Style
'Primero borramos la lista
For Each r In ActiveDocument.Styles
If r.Type = wdStyleTypeCharacter Or _
r.Type = wdStyleTypeParagraph Or _
r.Type = wdStyleTypeLinked Then
r.QuickStyle = False
End If
Next r
Dim s As Style
'Primero borramos la lista
For Each s In ActiveDocument.Styles
If s.NameLocal = "Recuerdas" Or s.NameLocal = "Respuestas" Or s.NameLocal = "Respuesta" _
Or s.NameLocal = "Recuerda" Or s.NameLocal = "Variado" Or s.NameLocal = "probando" Or _
s.NameLocal = "Titulo nivel 1" Or s.NameLocal = "Titulo nivel 2" Or s.NameLocal = "Titulo nivel 3" Or _
s.NameLocal = "Titulo nivel 4" Or s.NameLocal = "Titulo independiente" Or s.NameLocal = "Preguntas" Then
s.Delete
End If
Next s
End Sub
非常感謝,這是bieng在屁股痛。謝謝朋友! –