Visual Basic - Macro de word se cuelga a menudo

Life is soft - evento anual de software empresarial
   
Vista:

Macro de word se cuelga a menudo

Publicado por alfuco (1 intervención) el 25/11/2014 12:45:51
Buenas, os escribo porque he creado una macro para seleccionar solamente la parte de texto que hay a la derecha del "=" para poder importarla mas facilmente con otro programa (Trados). Un ejemplo seria el siguiente:

GlobalMsg.AAFMsg1=The application
GlobalMsg.AAFMsg2=is now activated.
GlobalMsg.AAFMsg3=It will be available
GlobalMsg.AAFMsg4=from
GlobalMsg.AAFMsg5=until
GlobalMsg.AAFMsg6=Your system needs to be connected to the Internet in order to use this option.

La macro selecciona "The aplication....... this option.", y se puede importar más rapidamente a este otro programa llamado Trados. El problema es que se cuelga mucho y normalmente tengo que reiniciar el ordenador para que siga funcionando correctamente. Supongo que debe ser un problema de optimizacion de la macro. ¿Alguien tiene alguna idea de como hacerlo? Os dejo aqui el codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
Attribute VB_Name = "NewMacros"
Sub ProtegerTexto()
 
'Proteger las líneas de comentarios
 
    Application.Run MacroName:="sAddTagStyles"
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Style = ActiveDocument.Styles("tw4winExternal")
    With Selection.Find
        .Text = "\#*^13"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .CorrectHangulEndings = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
 
'Proteger el código
        With Selection.Find
        .Text = "^13[!\=]@="
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .CorrectHan
gulEndings = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
 
'Proteger los saltos de línea
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Style = ActiveDocument.Styles("tw4winExternal")
    With Selection.Find
        .Text = "\n"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .CorrectHangulEndings = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .MatchFuzzy = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "\r"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .CorrectHangulEndings = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .MatchFuzzy = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
 
'Proteger las variables
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Fuente de párrafo predeter.")
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Style = ActiveDocument.Styles("tw4winInternal")
    With Selection.Find
        .Text = "\{*\}"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .CorrectHangulEndings = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Muchas gracias de antemano!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder