我正在编写的宏有问题。我需要将数据库(词汇表)中的导出文件转换为另一个标签结构,以便能够将其导入另一个数据库。
我做了几乎所有的步骤,但我遇到的麻烦是接下来的事情。大多数条目是双语的。但是,有些条目有多个值(最多 3 个)英文条目。
因此,我需要检查标签序列,如果发现双英文条目,则将其转换为两个条目。这个完成了。
问题在于,即使宏找到“正确”条目,它也不会忽略它并跳转到下一个条目,而是会尝试修改它,就好像它是错误的一样。
这是宏代码:
Sub CheckTagSequence()
'DECLARATION OF VARIABLES
Dim textline As String
Dim SourceLang, TargetLang, EntryID As String
Dim i As String
Dim objWdRange As String
'ASSIGNING VALUES TO THE VARIABLES
SourceLang = "<enTerm>"
TargetLang = "<frTerm>"
i = "<entry id="">"
'GO TO FIRST LINE
Selection.GoTo what:=gotoline, which:=GoToFirst
' MOVE DOWN TWO LINES
Selection.MoveDown unit:=wdLine, Count:=2
CONTINUA:
If Left(textline, 8) = i Then ID = textline
Selection.MoveDown unit:=wdLine, Count:=1
If Left(textline, 8) = "<subject" Then su = textline
Selection.MoveDown unit:=wdLine, Count:=1
If Left(textline, 8) = SourcLang Then en = textline
Selection.MoveDown unit:=wdLine, Count:=1
**If Left(textline, 8) = TargetLang Then fr = textline
Selection.MoveDown unit:=wdLine, Count:=1
If Left(textline, 8) = "</entry>" Then**
Selection.GoTo CONTINUA
ElseIf Left(textline, 8) = SourceLang Then GoTo CORREGGI
End If
CORREGGI:
Selection.MoveUp unit:=wdLine, Count:=3
Selection.HomeKey unit:=wdLine
Selection.MoveDown unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.Copy
Selection.MoveDown unit:=wdLine, Count:=1
Selection.Paste
Selection.MoveDown unit:=wdLine, Count:=1
Selection.MoveDown unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.Copy
Selection.MoveUp unit:=wdLine, Count:=3
Selection.HomeKey unit:=wdLine
Selection.Paste
Selection.MoveDown unit:=wdLine, Count:=1
If Left(textline, 8) = i Then GoTo CONTINUA
End Sub
它阻塞在这些行:
If Left(textline, 8) = TargetLang Then fr = textline
Selection.MoveDown unit:=wdLine, Count:=1
If Left(textline, 8) = "</entry>" Then
Selection.GoTo CONTINUA
这是一个示例文件的内容:
<?xml version=“1.0” encoding=“UTF-8”?>
<body>
<entry id=““>
<subject>IRECRUITMENT</subject>
<enTerm>Media Relations</enTerm>
<frTerm>Relations avec les médias</frTerm>
</entry>
<entry id=““>
<subject>IRECRUITMENT</subject>
<enTerm>OCEM</enTerm>
<frTerm>Relations avec les médias</frTerm>
</entry>
<entry id=““>
<subject>IRECRUITMENT</subject>
<enTerm>STATISTICS</enTerm>
<enTerm>FIPSS</enTerm>
<frTerm>STATISTIQUES</frTerm>
</entry>
<entry id=““>
<subject>IRECRUITMENT</subject>
<enTerm>3rd Nationality</enTerm>
<frTerm>3ème nationalité</frTerm>
</entry>
<entry id=””>
<subject>IRECRUITMENT</subject>
<enTerm>FINANCE</enTerm>
<enTerm>CSSDF</enTerm>
<frTerm>FINANCES</frTerm>
</entry>
</body>
预先感谢您的帮助!