我遇到了一個我正在編寫的宏的問題。我需要將導出文件從數據庫(術語表)轉換爲另一個標籤結構,以便能夠將其導入另一個數據庫。在xml數據庫中檢查標記序列用word vba導出
我做了幾乎所有的步驟,但我有什麼麻煩在做什麼,接下來。大多數條目都是雙語的。但是,有些條目具有多個值(最多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>
謝謝你提前尋求你的幫助!