How to recognize shading and border formatting in the following code?

N

Nomey

Could anybody tell me where/how a text box with blue or yellow shading, and grey borders are defined in the following code? I just want to change the shading color.

Best regards,
Nomey


=========code===========

Dim bParagraphAdded As Boolean
Dim bEndOfDocument As Boolean
Dim FindText$
Dim b_MatchWholeWord As Boolean
Dim b_Forward As Boolean
Dim b_MatchCase As Boolean
Dim b_MatchWildCards As Boolean
Dim b_MatchSoundsLike As Boolean
Dim b_MatchAllWordForms As Boolean

Dim n_MainHeight As Integer
Dim n_MainWidth As Integer
Dim n_MainLeft As Integer
Dim n_MainTop As Integer
Dim s_MainDocument As String
Dim n_CommandBars
Dim b_CommandBarsEnabled(255) As Boolean

Dim o_Footnote As Object
Dim n_InNote As Integer
Dim b_HasFootnotes As Boolean
Dim s_FNProcessed As String
Dim n_FootnoteHighlight As Integer
Dim n_SpaceBefore As Integer
Dim n_SpaceAfter As Integer
Dim n_LineSpacingRule As Integer
Dim n_LineSpacing As Integer

' XP specific
Dim bOldPasteSmartCutPaste As Boolean

Dim TWMessage$(12, 5)

'Dim oWorkbench As TW4Win.Application
Dim oWorkbench As Object

Declare Function FindWindowA Lib "User32" (ByVal Classname As String, _
ByVal WindowTtile As String) As Long
Declare Function SendMessageA Lib "User32" (ByVal Window As Long, _
ByVal Message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GlobalAddAtomA Lib "Kernel32" (ByVal Entry As String) As Long
Declare Function GlobalGetAtomNameA Lib "Kernel32" (ByVal Atom As Long, _
ByVal Buffer As String, ByVal Length As Long) As Long
Declare Sub GlobalDeleteAtom Lib "Kernel32" (ByVal Atom As Long)

Const WM_USER = 1024
Const VERSION = 600
Const ONEBOOKMARK = 0
Const ALREADYOPEN = 1
Const NOTHINGOPEN = 2
Const REVISIONON = 3
Const OPENFOOTNOTE = 4
Const PLACEDFNNOTEFOUND = 5
Public Const PROTECTED = 6
Public Const DONTCLOSEFNWINDOW = 7
Public Const PROTECTIONON = 8
Public Const PROTECTIONOFF = 9
Public Const SPELLCHECKCOMPLETE = 10
Public Const TUSTILLOPEN = 11

Dim EventHandler As New tw4winEventHandler
Dim FNWindowEventHandler As New tw4winFNWindowEventHandler

Public Sub Main()
End Sub
' XP specific method
Private Function bGetXPShowWindowsInTaskbar() As Boolean
bGetXPShowWindowsInTaskbar = Application.ShowWindowsInTaskbar
End Function
' generic method
Private Function bSDI() As Boolean
Dim iAppVersion As Long
iAppVersion = Val(Application.VERSION)

If iAppVersion < 9 Then
bSDI = False ' MDI mode for Word 97 and earlier
ElseIf iAppVersion = 9 Then
bSDI = True ' SDI mode for Word 2000
ElseIf iAppVersion >= 10 Then
bSDI = bGetXPShowWindowsInTaskbar() ' read XP's flag
End If
End Function

Private Sub DisableXPPasteSmartStyleBehavior(bDisable As Boolean)
With Application.Options
If bDisable Then
bOldPasteSmartCutPaste = .PasteSmartCutPaste
.PasteSmartCutPaste = False
Else ' restore
.PasteSmartCutPaste = bOldPasteSmartCutPaste
End If
End With
End Sub
' generic method
Private Sub DisablePasteSmartStyleBehavior(bDisable As Boolean)
If Val(Application.VERSION) >= 10 Then
DisableXPPasteSmartStyleBehavior bDisable
End If
End Sub
Private Function bWithinTable(rRange As Range) As Boolean
bWithinTable = False
For i = 1 To ActiveDocument.Tables.Count
With ActiveDocument.Tables(i)
If rRange.Start >= .Range.Start _
And rRange.End <= .Range.End Then
bWithinTable = True
Exit Function
End If
End With
Next i
End Function

Public Function fGetMessage$(n_ID)
If TWMessage$(0, 0) = "" Then
TWMessage$(0, 0) = "Bookmark 'tw4winFrom' xor 'tw4winUpto' " _
& "exists: Use 'Fix document' from the Trados menu!"
TWMessage$(1, 0) = "Translation Unit seems to be open: " _
& "close it before opening a new one!"
TWMessage$(2, 0) = "No Translation Unit seems to be open!"
TWMessage$(3, 0) = "You cannot use Workbench while Track Changes is on." _
+ Chr(13) + "* In Word 97 and 2000, deactivate 'Track changes while editing' under Tools/Track Changes/Highlight Changes..." _
+ Chr(13) + "* In Word XP, deactivate 'Track changes' under Tools."
TWMessage$(4, 0) = "You have to close footnote segment before continuing with main segment."
TWMessage$(5, 0) = "Couldn't find already placed footnote in target segment."
TWMessage$(6, 0) = "Protected tag!"
TWMessage$(7, 0) = "Use Alt+0 to close footnote window and to return to main segment."
TWMessage$(8, 0) = "Tag Protection ON"
TWMessage$(9, 0) = "Tag Protection OFF"
TWMessage$(10, 0) = "The spelling and grammar check is complete."
TWMessage$(11, 0) = "This command is not available because a translation unit is open."

TWMessage$(0, 1) = "Textmarke 'tw4winFrom' xor 'tw4winUpto' " _
& "existiert: Verwenden Sie 'Dokument reparieren' vom Menu Trados!"
TWMessage$(1, 1) = "Vermutlich ist noch eine ÜE geöffnet. " _
& "Schließen Sie sie, bevor Sie fortfahren."
TWMessage$(2, 1) = "Es ist anscheinend keine Übersetzungseinheit geöffnet."
TWMessage$(3, 1) = "Sie können mit Workbench nicht arbeiten, solange die Funktion 'Änderungen nachverfolgen' aktiv ist." + Chr(13) _
+ Chr(13) + "* In Word 97 und 2000 deaktivieren Sie die Option 'Änderungen während der Bearbeitung markieren' unter Extras/Änderungen verfolgen/Änderungen hervorheben..." _
+ Chr(13) + "* In Word XP deaktivieren Sie die Option 'Änderungen nachverfolgen' unter Extras."
TWMessage$(4, 1) = "Schließen Sie das Fußnotensegment, bevor Sie mit dem Hauptsegment fortfahren."
TWMessage$(5, 1) = "Die bereits plazierte Fußnote konnte im Zielsegment nicht gefunden werden."
TWMessage$(6, 1) = "Geschütztes Tag."
TWMessage$(7, 1) = "Verwenden Sie Alt+0, um das Fußnoten-Fenster zu schließen und zum Hauptsegment zurückzukehren."
TWMessage$(8, 1) = "Tag-Schutz an!"
TWMessage$(9, 1) = "Tag-Schutz aus!"
TWMessage$(10, 1) = "Die Rechtschreib- und Grammatikprüfung ist abgeschlossen."
TWMessage$(11, 1) = "Dieser Befehl ist nicht verfügbar, weil eine Übersetzungseinheit offen ist."


TWMessage$(0, 2) = "Signet 'tw4winFrom' xor 'tw4winUpto' " _
& "existe: Utiliser 'Rétablir document' de menu Trados !"
TWMessage$(1, 2) = "Unité de traduction semble ouverte : " _
& "fermer UT avant d'en ouvrir une autre !"
TWMessage$(2, 2) = "Aucune unité de traduction semble être ouverte !"
TWMessage$(3, 2) = "Vous ne pouvez pas utiliser le Workbench lorsque le mode Suivi des Modifications est activé." _
+ Chr(13) + "* Dans Word 97 et 2000, désactivez l'option 'Signaler les modifications lors de l'édition' sous Outils/Suivi des Modifications/Afficher les Modifications..." _
+ Chr(13) + "* Dans Word XP, désactivez l'option 'Suivi des modifications' sous Outils."
TWMessage$(4, 2) = "Fermez le segment de la note en bas de page avant de terminer le segment principal."
TWMessage$(5, 2) = "La note en bas de page déjà placée ne peut être trouvée dans le segment cible."
TWMessage$(6, 2) = "Balise protégée !"
TWMessage$(7, 2) = "Alt+0 pour fermer la fenêtre de la note en bas de page et pour retourner au segment principal."
TWMessage$(8, 2) = "Balises protégées!"
TWMessage$(9, 2) = "Balises non protégées!"
TWMessage$(10, 2) = "Vérification grammaticale et orthographique terminée."
TWMessage$(11, 2) = "Cette commande n'est pas disponible parce qu'une unité de traduction est ouverte."

TWMessage$(0, 3) = "ƒuƒbƒNƒ}[ƒN 'tw4winFrom' xor 'tw4winUpto' " _
& "‚ª‚ ‚è‚Ü‚·B: [trados]ƒƒjƒ…[‚©‚ç'•¶‘‚ÌC³'‚ð‚µ‚Ä‚­‚¾‚³‚¢! "
TWMessage$(1, 3) = "–|–ó’PˆÊ‚ªŠJ‚¢‚Ä‚¢‚Ü‚·B " _
& "V‚µ‚¢‚Ì‚ðŠJ‚­‘O‚ɕ‚¶‚Ä‚­‚¾‚³‚¢!"
TWMessage$(2, 3) = "–|–ó’PˆÊ‚ªŠJ‚©‚ê‚Ä‚¢‚Ü‚¹‚ñ!"
TWMessage$(3, 3) = "•ÏX—š—ð‚Ì•\Ž¦‚ªƒIƒ“‚Ì‚Æ‚«‚Í Workbench ‚ðŽg‚¦‚Ü‚¹‚ñB" _
+ Chr(13) + "‘±‚¯‚é‚É‚Í[ƒc[ƒ‹]ƒƒjƒ…[‚Ì[•ÏX—š—ð‚Ìì¬]‚Ì[•ÏX‰ÓŠ‚Ì•\Ž¦]‚Å" _
+ Chr(13) + "[•ÒW’†‚É•ÏX‰ÓŠ‚ð‹L˜^‚·‚é]‚ðƒIƒt‚É‚µ‚Ä‚­‚¾‚³‚¢B"
TWMessage$(4, 3) = "–{•¶ß‚É‚¤‚‚é‚É•›•¶ß‚ð•Â‚¶‚Ä‚­‚¾‚³‚¢B"
TWMessage$(5, 3) = "–󕶕¶ß‚É‚»‚Ì•›•¶ß‚ªŒ©‚‚©‚è‚Ü‚¹‚ñB"
TWMessage$(6, 3) = "‚±‚̃^ƒO‚̓vƒƒeƒNƒg‚³‚ê‚Ä‚¢‚Ü‚·!"
TWMessage$(7, 3) = "‹r’‚ð•Â‚¶‚Ä–{•¶‚É–ß‚é‚É‚Í Alt+0 ‚ð‰Ÿ‚µ‚Ä‚­‚¾‚³‚¢B"
TWMessage$(8, 3) = "ƒ^ƒOƒvƒƒeƒNƒVƒ‡ƒ“‚ª—LŒø‚É‚È‚Á‚Ä‚¢‚Ü‚·B"
TWMessage$(9, 3) = "ƒ^ƒOƒvƒƒeƒNƒVƒ‡ƒ“‚ª–³Œø‚É‚È‚Á‚Ä‚¢‚Ü‚·B"
TWMessage$(10, 3) = "The spelling and grammar check is complete."
TWMessage$(11, 3) = "–|–ó’PˆÊ‚ªŠJ‚©‚ê‚Ä‚¢‚邽‚ßA‚±‚̃Rƒ}ƒ“ƒh‚ÍŽg—p‚Å‚«‚Ü‚¹‚ñB"

TWMessage$(0, 4) = "El marcador 'tw4winFrom' xor 'tw4winUpto' " _
& "existe: Use la opción 'Arreglar documento' del menú Trados"
TWMessage$(1, 4) = "Parece que hay una unidad de traducción abierta: " _
& "ciérrela antes de abrir una unidad nueva."
TWMessage$(2, 4) = "No parece haber ninguna unidad de traducción abierta."
TWMessage$(3, 4) = "No se puede usar Workbench mientras el modo de Control de Cambios está activado." _
+ Chr(13) + "* En Word 97 y 2000, desactive Herramientas/Control de cambios/Aceptar antes de continuar." _
+ Chr(13) + "* En Word XP, desactive Herramientas/Control de cambios."
TWMessage$(4, 4) = "Debe cerrar el segmento de la nota al pie antes de continuar con el segmento principal."
TWMessage$(5, 4) = "No se ha podido encontrar la nota al pie colocada en el segmento de destino."
TWMessage$(6, 4) = "Etiqueta protegida."
TWMessage$(7, 4) = "Use Alt+0 para cerrar la ventana de la nota al pie y volver al segmento principal."
TWMessage$(8, 4) = "Protección de etiquetas desactivada!"
TWMessage$(9, 4) = "Protección de etiquetas activada!"
TWMessage$(10, 4) = "La verificación ortográfica y gramatical ha finalizado."
TWMessage$(11, 4) = "El comando no está disponible porque una unidad de traducción está abierta."

TWMessage$(0, 5) = "´æÔÚÊéÇ© tw4winFrom ºÍ/»ò tw4winUpto£º " _
& "ÇëʹÓà Trados ²Ëµ¥Éϵġ°ÐÞ¸´Îĵµ¡±ÃüÁî¡£"
TWMessage$(1, 5) = "´æÔÚδ¹Ø±ÕµÄ·­Òëµ¥Ôª£º" _
& "ÇëÏȽ«Æä¹Ø±Õ£¬²ÅÄÜ´ò¿ªÐµķ­Òëµ¥Ôª£¡"
TWMessage$(2, 5) = "ûÓдò¿ªµÄ·­Òëµ¥Ôª£¡"
TWMessage$(3, 5) = "ÐÞ¶©¹¦ÄÜ´ò¿ªÊ±£¬ÎÞ·¨Ê¹Óà Workbench¡£" _
+ Chr(13) + "* ÔÚ Word 97 ºÍ 2000 ÖУ¬Çëµ¥»÷¡°¹¤¾ß¡±£­¡°ÐÞ¶©¡±£­¡°Í»³öÏÔʾÐÞ¶©¡±Í£Óøù¦ÄÜ¡£" _
+ Chr(13) + "* ÔÚ Word 2002 ÖУ¬Çëµ¥»÷¡°¹¤¾ß¡±£­¡°ÐÞ¶©¡±Í£Óøù¦ÄÜ¡£"
TWMessage$(4, 5) = "ÔÚ¼ÌÐø·­ÒëÖ÷¾ä¶Î֮ǰ£¬±ØÐëÏȹرսÅ×¢¾ä¶Î¡£"
TWMessage$(5, 5) = "ÔÚÄ¿±ê¾ä¶ÎÖÐÎÞ·¨ÕÒµ½ÒÑ·ÅÖõĽÅ×¢¡£"
TWMessage$(6, 5) = "Êܱ£»¤µÄ±ê¼Ç£¡"
TWMessage$(7, 5) = "ÇëʹÓà Alt+0 ¹Ø±Õ½Å×¢´°¿Ú£¬·µ»ØÖ÷¾ä¶Î¡£"
TWMessage$(8, 5) = "±ê¼Ç±£»¤´¦ÓÚ´ò¿ª×´Ì¬"
TWMessage$(9, 5) = "±ê¼Ç±£»¤´¦ÓڹرÕ״̬"
TWMessage$(10, 5) = "The spelling and grammar check is complete."
TWMessage$(11, 5) = "This command is not available because a translation unit is open."

End If

nLang = Val(Application.International(wdProductLanguageID))

If nLang = 1031 Or nLang = 2055 Then
n_Language = 1
ElseIf nLang = 1036 Or nLang = 3084 Then
n_Language = 2
ElseIf nLang = 1041 Then
n_Language = 3
ElseIf nLang = 1034 Or nLang = 2058 Then
n_Language = 4
ElseIf nLang = 2052 Then
n_Language = 5
Else
n_Language = 0
End If

msg$ = TWMessage$(n_ID, n_Language)
If msg$ = "" Then
fGetMessage$ = TWMessage$(n_ID, 0)
Else
fGetMessage$ = msg$
End If
End Function

Public Sub sMessage(n_message As Integer, b_beep As Boolean)
StatusBar = fGetMessage$(n_message)

If b_beep = True Then
Beep
End If
End Sub

Public Function fMainSegment()
b_ReplaceSelection = Options.ReplaceSelection
Options.ReplaceSelection = True

If n_InNote > 10 Then
' no main segment exists
a = bCloseFootnoteWindow()
GoTo eMainSegment
End If

If bCloseFootnoteWindow() = False Then
GoTo eMainSegment
End If

If bCheckStatus(False) = False Then
GoTo eMainSegment
End If

fMainSegment = fRequest("current", "MainSegment#0#")

eMainSegment:
Options.ReplaceSelection = b_ReplaceSelection
End Function


Public Function fSubSegment(n_SubSegment)

aClip = tw4winMain.fSaveClipboardContents(sClip)

System.Cursor = wdCursorWait
Application.ScreenUpdating = False

b_ShowHidden = ActiveWindow.View.ShowHiddenText
ActiveWindow.View.ShowHiddenText = True

b_ReplaceSelection = Options.ReplaceSelection
Options.ReplaceSelection = True

If bCheckStatus(False) = False Then
GoTo eSubSegment
End If

Selection.Collapse
ActiveDocument.Bookmarks.Add Name:="tw4winHere"

Selection.Start = ActiveDocument.Bookmarks("tw4winFrom").Range.Start
Selection.Collapse
Selection.MoveDown wdParagraph, 1
n_From = Selection.Start

Selection.Start = ActiveDocument.Bookmarks("tw4winUpto").Range.Start
Selection.Collapse
Selection.MoveUp wdParagraph, 1
n_Upto = Selection.Start

Dim o_Current As Range
Set o_Current = ActiveDocument.Range(n_From, n_Upto)
o_Current.TextRetrievalMode.IncludeHiddenText = True

s_SubSegment = Mid$(Str$(n_SubSegment), 2)
s_Tag = "{" & s_SubSegment & ">"
o_Current.Find.Execute FindText:=s_Tag
o_Current.Select

' Find.Found crashes under Hebrew/Arabic Word
If o_Current.Text = s_Tag Then
Selection.Collapse wdCollapseEnd
n_SelInfo = Selection.Information(wdReferenceOfType)
If n_SelInfo = 1 Or n_SelInfo = 2 Then
' copy source foonote
o_Current.End = n_Upto
Set o_Footnote = fGetNote(n_SelInfo, o_Current)
o_Current.End = o_Footnote.Reference.End + 3
If Right(o_Current.Text, 1) <> "}" Then
o_Current.End = o_Current.End + 1
End If
o_Current.Copy

'replace source foontnote with placeholder
o_Footnote.Reference.Select
If n_SelInfo = 1 Then
Selection.TypeText "fn"
Else
Selection.TypeText "en"
End If

o_Current.Start = o_Current.End
aNumber = o_Current.MoveEnd(wdParagraph, 3)

o_Current.Find.Execute FindText:=s_Tag
If o_Current.Text <> s_Tag Then
' new footnote, copy to target
Selection.GoTo What:=wdGoToBookmark, Name:="tw4winHere"
Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=5, Extend:=wdExtend
Set o_Footnote = fGetNote(n_SelInfo, Selection.Range)
Selection.Collapse
Else
o_Current.End = n_Upto
Set o_Footnote = fGetNote(n_SelInfo, o_Current)
End If
n_InNote = n_SelInfo
s_FNProcessed = s_FNProcessed & "," & s_SubSegment & ","
Else
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
If Selection.Text = "fn" Or Selection.Text = "en" Then
If Selection.Text = "fn" Then
n_SelInfo = 1
Else
n_SelInfo = 2
End If
'already placed footnote
o_Current.Start = Selection.End
aNumber = o_Current.MoveEnd(wdParagraph, 3)

o_Current.Find.Execute FindText:=s_Tag
If o_Current.Text = s_Tag Then
o_Current.End = n_Upto
Set o_Footnote = fGetNote(n_SelInfo, o_Current)

n_InNote = n_SelInfo
s_FNProcessed = s_FNProcessed & "," & s_SubSegment & ","
Else
Selection.Start = ActiveDocument.Bookmarks("tw4winHere").Range.Start
Selection.Collapse
ActiveDocument.Bookmarks("tw4winHere").Delete
sMessage PLACEDFNNOTEFOUND, True
GoTo eSubSegment
End If
End If
End If
End If

Selection.Start = ActiveDocument.Bookmarks("tw4winHere").Range.Start
Selection.Collapse
ActiveDocument.Bookmarks("tw4winHere").Delete

If o_Footnote Is Nothing Then
i_Result = fRequest("current", "SubSegment#" & s_SubSegment & "#")
If Abs(i_Result) Mod 100 >= 10 Then
sGotoIndexBegin
End If
Else
If o_Footnote.Range.Text = "" Then
Beep
Else
ActiveWindow.View.ShowHiddenText = b_ShowHidden
sOpenFootnoteWindow (0)
If fNextTextParagraph() = 0 Then
b_close = bCloseFootnoteWindow()
Beep
Else
i_Result = fRequest("open", "Open#1#")
End If
End If
End If

fSubSegment = i_Result

tw4winMain.fRestoreClipboardContents (sClip)


eSubSegment:
Application.ScreenUpdating = True
System.Cursor = wdCursorNormal

ActiveWindow.View.ShowHiddenText = b_ShowHidden
Options.ReplaceSelection = b_ReplaceSelection
End Function


Private Sub sOpenFootnoteWindow(n_Offset)
Set EventHandler.App = Word.Application

s_MainDocument = ActiveDocument.Name
ActiveWindow.SplitVertical = 0

If bSDI() Then
n_MainHeight = Application.Height
n_MainWidth = Application.Width
n_MainLeft = Application.Left
n_MainTop = Application.Top
Else
n_WordHeight = Application.UsableHeight
n_WordWidth = Application.UsableWidth

Dim o_MainDoc As Document
Set o_MainDoc = ActiveDocument

Dim o_MainWin As Window
Set o_MainWin = o_MainDoc.ActiveWindow

With o_MainWin
n_MainHeight = .Height
n_MainWidth = .Width
n_MainLeft = .Left
n_MainTop = .Top
End With
End If

n_FootnoteHighlight = o_Footnote.Reference.HighlightColorIndex
o_Footnote.Reference.HighlightColorIndex = wdYellow

Dim o_FootnoteDoc As Document

On Error Resume Next
Set o_FootnoteDoc = Documents("TW4Win Footnote.doc")
If o_FootnoteDoc Is Nothing Then
Set o_FootnoteDoc = Documents.Add
sFootnoteDoc$ = Options.DefaultFilePath(wdTempFilePath) + "\TW4Win Footnote.doc"
o_FootnoteDoc.SaveAs FileName:=sFootnoteDoc$, AddToRecentFiles:=False
Else
o_FootnoteDoc.Activate
End If

Dim o_FootnoteWin As Window
Set o_FootnoteWin = Windows(o_FootnoteDoc.Name)

If bSDI() Then
Windows(s_MainDocument).Activate

n_CommandBars = 0
For Each cbar In CommandBars
n_CommandBars = n_CommandBars + 1
b_CommandBarsEnabled(n_CommandBars) = cbar.Enabled
If cbar.Enabled = True Then cbar.Enabled = False
Next

n_Height = n_MainHeight / 3
Application.Height = n_Height
Application.ScreenUpdating = True
Application.ScreenRefresh
Application.ScreenUpdating = False

o_FootnoteDoc.Activate
Application.Move Left:=n_MainLeft, Top:=n_MainTop + n_Height
Application.Resize Width:=n_MainWidth, Height:=n_MainHeight - n_Height
Else
n_NewMainHeight = Application.UsableHeight / 3
With o_MainWin
.Left = 0
.Top = 0
.Height = n_NewMainHeight
.Width = Application.UsableWidth
End With
With o_FootnoteWin
.Left = 0
.Top = n_NewMainHeight + 1
.Height = Application.UsableHeight - n_NewMainHeight
.Width = Application.UsableWidth
End With
End If

ActiveDocument.Range.FormattedText = o_Footnote.Range.FormattedText
ActiveDocument.Range.ParagraphFormat = o_Footnote.Range.ParagraphFormat

Selection.Start = n_Offset
End Sub


Private Function bCloseFootnoteWindow()
Set EventHandler.App = Nothing
Set FNWindowEventHandler.App = Word.Application

On Error Resume Next
n_Offset = 0
Set o_FootnoteDoc = Documents("TW4Win Footnote.doc")
If Not (o_FootnoteDoc Is Nothing) Then
If o_FootnoteDoc = Empty Then
bCloseFootnoteWindow = False
Exit Function
End If
If n_InNote > 0 Then
If ActiveDocument.Bookmarks.Exists("tw4winFrom") <> 0 Or _
ActiveDocument.Bookmarks.Exists("tw4winUpto") <> 0 Then
sMessage OPENFOOTNOTE, True
bCloseFootnoteWindow = False
Exit Function
End If

ActiveWindow.View.ShowHiddenText = True

o_FootnoteDoc.Activate
n_Offset = Selection.Start

o_Footnote.Range.FormattedText = o_FootnoteDoc.Range.FormattedText
Set o_Range = o_Footnote.Range
o_Range.Collapse (wdCollapseEnd)
o_Range.Delete wdCharacter, -1

o_Footnote.Reference.HighlightColorIndex = n_FootnoteHighlight
o_Footnote.Reference.Select
End If

sFootnoteDoc$ = o_FootnoteDoc.FullName
o_FootnoteDoc.Close wdDoNotSaveChanges
Kill sFootnoteDoc$
Set o_Footnote = Nothing
End If

On Error Resume Next
Set o_MainWin = Windows(s_MainDocument)
If Not (o_MainWin Is Nothing) Then
o_MainWin.Activate

If bSDI() Then
Application.Resize Width:=n_MainWidth, Height:=n_MainHeight
Application.ScreenUpdating = True
Application.ScreenRefresh
Application.ScreenUpdating = False
n_CommandBars = 0
For Each cbar In CommandBars
n_CommandBars = n_CommandBars + 1
If b_CommandBarsEnabled(n_CommandBars) = True Then
cbar.Enabled = True
End If
Next
Else
With o_MainWin
.Left = n_MainLeft
.Top = n_MainTop
.Height = n_MainHeight
.Width = n_MainWidth
End With
End If

If n_InNote Mod 10 = 1 Then
ActiveWindow.View.SplitSpecial = wdPaneFootnotes
ElseIf n_InNote Mod 10 = 2 Then
ActiveWindow.View.SplitSpecial = wdPaneEndnotes
End If

If n_InNote < 10 Then
ActiveWindow.ActivePane.Next.Activate
ElseIf n_InNote < 100 Then
ActiveWindow.ActivePane.Next.Activate
Selection.Collapse wdCollapseEnd
Else
Selection.Start = fGetNote(n_InNote, Selection.Range).Range.Start + n_Offset
End If
End If

Set EventHandler.App = Word.Application
Set FNWindowEventHandler.App = Nothing

n_InNote = 0
bCloseFootnoteWindow = True
End Function


Public Function bCheckStatus(b_Open As Boolean)
bCheckStatus = False

n_Exists = ActiveDocument.Bookmarks.Exists("tw4winFrom") _
+ ActiveDocument.Bookmarks.Exists("tw4winUpto")

If n_Exists = -1 Then
If ActiveDocument.Bookmarks.Exists("tw4winFrom") Then
Selection.GoTo What:=wdGoToBookmark, Name:="tw4winFrom"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="tw4winUpto"
End If
sMessage ONEBOOKMARK, True
Exit Function
End If

If b_Open = True Then
If n_Exists Then
Selection.GoTo What:=wdGoToBookmark, Name:="tw4winFrom"
Selection.MoveDown wdParagraph, 3
sMessage ALREADYOPEN, True
Exit Function
End If
'save selection, because in rtl tables following command moves it?!
'nStart = Selection.Start
'nEnd = Selection.End
ActiveDocument.Bookmarks.Add ("tw4winHere")
bRevisionMarking = ActiveDocument.Content.Information(wdRevisionMarking)
'Selection.End = nEnd
'Selection.Start = nStart
ActiveDocument.Bookmarks("tw4winHere").Select
ActiveDocument.Bookmarks("tw4winHere").Delete
If bRevisionMarking Then
MsgBox fGetMessage$(REVISIONON), vbOKOnly + vbInformation, "TRADOS Translator's Workbench"
Exit Function
End If
Else
If n_Exists = 0 Then
sMessage NOTHINGOPEN, True
Exit Function
End If
End If

bCheckStatus = True

End Function


Public Function fFindNextNo100()
While 1
If fFindNextNo100Segment() = 0 Then
fFindNextNo100 = 0
If n_InNote = 0 Then
GoTo quit
ElseIf n_InNote < 10 Then
'subsegment footnote
i_Result = tw4winMain.fMainSegment()
GoTo quit
ElseIf n_InNote < 100 Then
'standalone footnote
i_Result = fMainSegment()
Else
'Open in footnote pane without mainsegment
GoTo quit
End If
Else
fFindNextNo100 = 1
n_SelInfo = Selection.Information(wdReferenceOfType)

If n_SelInfo = 1 Or n_SelInfo = 2 Then
n_InNote = 10 + n_SelInfo

Set o_Footnote = fGetNote(n_InNote, ActiveDocument.Range(Selection.Start))

sOpenFootnoteWindow (0)
Else
GoTo quit
End If
End If
Wend

quit:

End Function


Public Function fFindNextNo100Segment()
Dim n_Current As Long

Set o_DocRange = Selection.Range
o_DocRange.Expand (wdStory)

n_EndOfDocument = o_DocRange.End
b_ScreenUpdating = Application.ScreenUpdating
Application.ScreenUpdating = False
b_ShowHidden = ActiveWindow.View.ShowHiddenText
ActiveWindow.View.ShowHiddenText = True

n_UpdateCounter = 1

sPushFindSettings
With Selection.Find
.MatchWholeWord = False
.MatchCase = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Wrap = wdFindStop
End With

Selection.Find.ClearFormatting

fFindNextNo100Segment = 1

While 1
If fNextTextParagraph() = 0 Then
n_Current = Selection.Start
fFindNextNo100Segment = 0
GoTo eFindNextNo100
End If

n_Current = Selection.Start
Selection.Collapse
Selection.Find.Execute FindText:="<0}", Forward:=True
If Selection.Text <> "<0}" Then
GoTo eFindNextNo100
End If
n_EndOfMainSegment = Selection.End

Selection.Start = n_Current
Selection.Find.Execute FindText:="{0>"
n_BeginOfMainSegment = n_EndOfDocument
If Selection.Text = "{0>" Then
n_BeginOfMainSegment = Selection.Start
End If

If n_BeginOfMainSegment = n_EndOfDocument _
Or n_BeginOfMainSegment > n_EndOfMainSegment Then
Selection.Start = n_Current
Selection.Collapse
Selection.Find.Execute FindText:="{0>", Forward:=False
If Selection.Text <> "{0>" Then
Rem tagging error, leave loop
GoTo eFindNextNo100
End If
n_BeginOfMainSegment = Selection.Start
End If

If n_Current < n_BeginOfMainSegment Then
Rem virgin source
GoTo eFindNextNo100
End If

Selection.Collapse
Selection.Find.Execute FindText:="<}", Forward:=True
If Selection.Text <> "<}" Then
Rem tagging error
GoTo eFindNextNo100
End If

Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend

If Val(Selection.Text) < 100 Then
Rem fuzzy match
GoTo eFindNextNo100
End If

Selection.Start = n_EndOfMainSegment
Selection.End = n_EndOfMainSegment + 1

If Selection.Start <> n_EndOfMainSegment Then
'end of table cell marker
Selection.Collapse wdCollapseEnd
End If

If n_UpdateCounter > 10 Then
Application.ScreenUpdating = True
Application.ScreenRefresh
Application.ScreenUpdating = False
n_UpdateCounter = 1
Else
n_UpdateCounter = n_UpdateCounter + 1
End If
Wend


eFindNextNo100:
Selection.Start = n_Current
Selection.Collapse
'Florin: the following line seems to fix Samsa #2767
Selection.Start = n_Current

Application.ScreenUpdating = b_ScreenUpdating
ActiveWindow.View.ShowHiddenText = b_ShowHidden
sPopFindSettings
End Function


Public Function fNextTextParagraph()
fNextTextParagraph = 0

Set o_Range = Selection.Range
o_Range.Expand (wdStory)

o_Range.TextRetrievalMode.IncludeHiddenText = True
o_Range.TextRetrievalMode.IncludeFieldCodes = True
o_Range.Start = Selection.Start

Set o_Char = o_Range.Characters.First
n_End = o_Range.Characters.Last.Start
For i = o_Char.Start To n_End
i_value = Asc(o_Char.Text)
If o_Char.Style = "tw4winExternal" Or o_Char.Style = "tw4winInternal" Then
o_Char.Select
Do
n_SelEnd = Selection.End
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
If n_SelEnd = Selection.End Then
Exit For
End If
If Selection.Style Is Nothing Then
Exit Do
End If
Loop While Selection.Style = "tw4winExternal" Or Selection.Style = "tw4winInternal"
o_Char.Start = n_SelEnd - 1
o_Char.End = n_SelEnd
ElseIf (i_value > 65 And i_value < 91) Or (i_value > 96) Or _
(i_value = 63 And AscW(o_Char.Text) <> 63) Then
fNextTextParagraph = -1
Exit For
ElseIf i_value = 65 Then
' Check on see also footnotes (RTF help)
' Use Selection instead of o_Char to avoid repagination in XP
Selection.Start = o_Char.Start
Selection.End = Selection.Start
n_Note = Selection.Information(wdReferenceOfType)
If n_Note = 1 Or n_Note = 2 Then
s_Ref = fGetNote(n_Note, ActiveDocument.Range(o_Char.Start)).Reference.Text
If s_Ref <> "A" Then
fNextTextParagraph = -1
Exit For
End If
Else
fNextTextParagraph = -1
Exit For
End If
ElseIf i_value <= 2 Then
If Selection.StoryType <> wdFootnotesStory And _
Selection.StoryType <> wdEndnotesStory Then
fNextTextParagraph = -1
Exit For
End If
ElseIf i_value = 36 Then
' Check on dollar footnotes (RTF help)
' Use Selection instead of o_Char to avoid repagination in XP
Selection.Start = o_Char.Start
Selection.End = Selection.Start
n_Note = Selection.Information(wdReferenceOfType)
If n_Note = 1 Or n_Note = 2 Then
fNextTextParagraph = -1
Exit For
End If
End If
Set o_Char = o_Char.Next
Next i
If i < n_End Then
o_Char.Select
End If
End Function

Public Function fRequest(pMode$, pCommand$)
Dim aLanguage$
Dim ParagraphBookmarks
Dim BookmarkNames(1 To 50) As String
Dim CurrentParagraph As Range

Set o_DocRange = Selection.Range
o_DocRange.Expand (wdStory)

Dim bOldPasteSmartStyleBehaviour As Boolean
' disable XP's smart cut&paste options
DisablePasteSmartStyleBehavior True

b_ShowHidden = ActiveWindow.View.ShowHiddenText
ActiveWindow.View.ShowHiddenText = True
With Options
b_SmartCutPaste = .SmartCutPaste
.SmartCutPaste = False
b_ReplaceSelection = .ReplaceSelection
.ReplaceSelection = True
b_TabIndentKey = .TabIndentKey
.TabIndentKey = False
End With

i_Result = 0

If Selection.StoryType = wdTextFrameStory Then
' on Word XP, the below Selection.EscapeKey will reset Start = End = 0 instead
' of collapsing to the current Start/End.
Selection.End = Selection.Start
Else
Selection.EscapeKey
Selection.Collapse
End If

If Selection.StoryType = wdFootnotesStory Or Selection.StoryType = wdEndnotesStory Then
ActiveWindow.ActivePane.Next.Activate
End If

aLanguage$ = WordBasic.AppInfo$(16)

Dim b_Open As Boolean
If pMode$ = "open" Then
b_Open = True
bParagraphAdded = False
Else
b_Open = False
End If

If bCheckStatus(b_Open) = False Then
GoTo eRequest
End If

Rem asign current paragraph to a range
If pMode$ = "open" Then
Set CurrentParagraph = Selection.PARAGRAPHS(1).Range

If n_InNote = 0 Then
With CurrentParagraph.ParagraphFormat
n_SpaceBefore = .SpaceBefore
n_SpaceAfter = .SpaceAfter
n_LineSpacing = .LineSpacing
n_LineSpacingRule = .LineSpacingRule
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = 0
End With
End If

bEndOfDocument = False
Else
Set CurrentParagraph = o_DocRange.Duplicate
CurrentParagraph.Start = o_DocRange.Bookmarks("tw4winFrom").Range.Start
CurrentParagraph.End = o_DocRange.Bookmarks("tw4winUpto").Range.End
End If

CurrentParagraph.TextRetrievalMode.IncludeHiddenText = True
CurrentParagraph.TextRetrievalMode.IncludeFieldCodes = True

Rem assign next paragraph (for file inserts)
If CurrentParagraph.End = o_DocRange.End Then
CurrentParagraph.InsertParagraphAfter
CurrentParagraph.End = CurrentParagraph.End - 1
CurrentParagraph.Characters.Last.Font.Reset
bEndOfDocument = True
End If

Rem if in field leave it
If pMode$ = "open" Or pMode$ = "current" Then
For i = 1 To CurrentParagraph.Fields.Count
Set o_Field = CurrentParagraph.Fields(i)

nStart = o_Field.Code.Start
If o_Field.Kind = wdFieldKindHot Or o_Field.Kind = wdFieldKindWarm Then
nEnd = CurrentParagraph.Fields(i).Result.End
Else
nEnd = CurrentParagraph.Fields(i).Code.End
End If

If nStart <= Selection.Start And nEnd >= Selection.End Then
Selection.Start = nStart - 1
Selection.End = Selection.Start
Exit For
End If
Next i
Else
Selection.Start = o_DocRange.Bookmarks("tw4winFrom").Range.Start
Selection.Collapse
Selection.MoveDown wdParagraph, 3
If Selection.Text = "<" And Selection.Style = "tw4winMark" Then
Selection.MoveDown wdParagraph, 1
End If
End If

'Check on missing paragraph mark (table cells)
'save selection, because in rtl tables following commands move it?!

'nStart = Selection.Start
'nEnd = Selection.End
ActiveDocument.Bookmarks.Add ("tw4winHere")

Set o_Char = CurrentParagraph.Characters.Last.Next
bTableWithoutPar = Asc(Right$(CurrentParagraph.Text, 1)) = 7

Dim bAddParagraph As Boolean
bAddParagraph = bTableWithoutPar
If Not bAddParagraph And ActiveDocument.Tables.Count <> 0 Then
' Use Selection to avoid repagination in Word XP
Selection.Start = o_Char.Start - 1
Selection.End = Selection.Start
If Not Selection.Information(wdWithInTable) Then
Selection.Start = o_Char.Start
Selection.End = Selection.Start
If Selection.Information(wdWithInTable) Then
bAddParagraph = True
End If
End If
End If

ActiveDocument.Bookmarks("tw4winHere").Select
ActiveDocument.Bookmarks("tw4winHere").Delete
'Selection.End = nEnd
'Selection.Start = nStart

Rem save bookmarks
Set ParagraphBookmarks = CurrentParagraph.Bookmarks
bShowHidden = ParagraphBookmarks.ShowHidden
ParagraphBookmarks.ShowHidden = True
BookmarkCount = ParagraphBookmarks.Count
If BookmarkCount > 50 Then
BookmarkCount = 50
End If
For i = BookmarkCount To 1 Step -1
If Left$(ParagraphBookmarks(i).Name, 6) <> "tw4win" Then
BookmarkNames(i) = ParagraphBookmarks(i).Name
o_DocRange.Bookmarks(ParagraphBookmarks(i)).Delete
End If
Next i

Rem insert current marker
n_char = Asc(Selection.Text)
If n_char = 13 Or n_char = 10 Then
Selection.TypeText Chr(30) & "{}" & Chr(30)
Else
Selection.CopyFormat
Selection.TypeText Chr(30) & "{}" & Chr(30)
Selection.MoveLeft Unit:=wdCharacter, Count:=4, Extend:=wdExtend
Selection.PasteFormat
End If

Rem Word 8.0 without SR1 doesn't copy leading hidden text
Rem unhide first char if it's our start segment marker
If Left$(CurrentParagraph.Text, 3) = "{0>" Then
Set o_First = o_DocRange.Duplicate
o_First.Start = CurrentParagraph.Start
o_First.End = CurrentParagraph.Start + 1
o_First.Font.Hidden = 0
Else
Set o_First = Nothing
End If

Rem insert paragraph if necessary and copy to clipboard
If bAddParagraph Then
Selection.Start = CurrentParagraph.End - 1
Selection.Collapse
If bTableWithoutPar Then
Selection.TypeParagraph
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Reset
Else
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Paste
End If
CurrentParagraph.End = CurrentParagraph.End - 1
CurrentParagraph.Copy
CurrentParagraph.End = CurrentParagraph.End - 1
bParagraphAdded = True
Else
CurrentParagraph.Copy
End If

'reset first char
If Not (o_First Is Nothing) Then
o_First.Font.Hidden = 1
End If

'Check Bidi alignment
If Not (b_Open) Then
BidiTest = wdReadingOrderLtr
If Not (BidiTest = Empty) Then
tw4winBidiAlignment.Check CurrentParagraph
End If
End If


'start processing in Workbench
i_Result = fExecute(pCommand$)
If i_Result < 0 Then
If i_Result <= -10000 Then
'no pasting
i_Result = i_Result + 10000
ElseIf i_Result <= -1000 Then
'RTF text contains fields which are not translated via clipboard xfer
i_Result = i_Result + 1000
n_LeftIndent = CurrentParagraph.ParagraphFormat.LeftIndent
Selection.Start = CurrentParagraph.End
Selection.Collapse
Selection.TypeParagraph

'save selection, because in rtl tables strange things happen to it
ActiveDocument.Bookmarks.Add ("tw4winHere")

b_confirm = Options.ConfirmConversions
CurrentParagraph.InsertFile _
FileName:=Options.DefaultFilePath(wdTempFilePath) & "\$xfer.rtf", _
ConfirmConversions:=False
Options.ConfirmConversions = b_confirm
'Kill Options.DefaultFilePath(wdTempFilePath) & "\$xfer.rtf"

'restore selection position
Set o_Bookmark = ActiveDocument.Bookmarks("tw4winHere")
Selection.End = o_Bookmark.Range.End
Selection.Start = o_Bookmark.Range.Start
o_Bookmark.Delete

Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Delete
CurrentParagraph.End = Selection.End
CurrentParagraph.ParagraphFormat.LeftIndent = n_LeftIndent
Else
CurrentParagraph.Paste
' circumvent bug in Word XP (during Paste, CurrentParagraph's .Range
' is not adjusted correctly if at end of document/story within text boxes)
If CurrentParagraph.StoryType = wdTextFrameStory And bEndOfDocument Then
CurrentParagraph.End = o_DocRange.End
End If
End If

If (pMode$ = "close" Or pMode$ = "open" Or Abs(i_Result) Mod 10 = 9) And _
(bAddParagraph Or bParagraphAdded) Then
If bAddParagraph Then
Selection.Start = CurrentParagraph.End + 1
Else
Selection.Start = CurrentParagraph.End
End If

Selection.TypeBackspace
End If
ElseIf bAddParagraph Then
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
Selection.TypeBackspace
End If

Rem replace current mark
bMarkerDeleted = False
Selection.Start = CurrentParagraph.Start
Selection.Collapse
Selection.Find.ClearFormatting
sPushFindSettings
Selection.Find.MatchWildcards = False
Selection.Find.Forward = True
Selection.Find.Execute FindText:=Chr(30) & "{}" & Chr(30)
If Selection.Text = Chr(30) & "{}" & Chr(30) Then
Selection.Delete
bMarkerDeleted = True
End If
sPopFindSettings

bOpen = False
If i_Result > -1 Then
If pMode$ <> "open" Then
bOpen = True
Else
sRestoreSpacing CurrentParagraph.ParagraphFormat
End If
Else
If pMode$ = "close" Or Abs(i_Result) Mod 10 = 9 Then
sRestoreSpacing CurrentParagraph.ParagraphFormat

If o_DocRange.Bookmarks.Exists("tw4winFrom") Then
o_DocRange.Bookmarks("tw4winFrom").Delete
End If
If o_DocRange.Bookmarks.Exists("tw4winUpto") Then
o_DocRange.Bookmarks("tw4winUpto").Delete
End If

bParagraphAdded = False

If bEndOfDocument = True Then
aEnd = Selection.PARAGRAPHS(1).Range.End
Set o_Range = o_DocRange.Duplicate
o_Range.Start = aEnd - 1
o_Range.End = aEnd
o_Range.Delete
bEndOfDocument = False
End If

If n_InNote = 0 Then
s_FNProcessed = ""
End If
Else
bOpen = True
End If
End If

'set tw4win bookmarks
If bOpen = True Then
'ensure the tw4win fields are visible
If bMarkerDeleted = True Then
n_Current = Selection.Start
Selection.MoveUp Unit:=wdParagraph, Count:=3, Extend:=wdMove
Selection.Start = n_Current
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdMove
Selection.End = n_Current
End If
nStart = CurrentParagraph.Start
nEnd = CurrentParagraph.End
Set o_Range = o_DocRange.Duplicate
o_Range.Start = nStart
o_Range.End = nStart
o_DocRange.Bookmarks.Add Name:="tw4winFrom", Range:=o_Range
o_Range.Start = nEnd
o_Range.End = nEnd
o_DocRange.Bookmarks.Add Name:="tw4winUpto", Range:=o_Range

If i_Result < 0 Then
sSetPane (i_Result)
End If
End If

Rem reinsert bookmarks
For i = 1 To BookmarkCount
mark$ = BookmarkNames(i)
If Len(mark$) > 0 And Left$(BookmarkNames(i), 6) <> "tw4win" Then
ParagraphBookmarks.Add Name:=BookmarkNames(i)
End If
Next i
ParagraphBookmarks.ShowHidden = bShowHidden

eRequest:
On Error GoTo -1: On Error GoTo 0

ActiveWindow.View.ShowHiddenText = b_ShowHidden
Options.SmartCutPaste = b_SmartCutPaste
Options.ReplaceSelection = b_ReplaceSelection
Options.TabIndentKey = b_TabIndentKey
DisablePasteSmartStyleBehavior False

fRequest = i_Result
End Function

Private Sub sRestoreSpacing(o_Format As ParagraphFormat)
If n_InNote = 0 Then
On Error Resume Next
With o_Format
.SpaceBefore = n_SpaceBefore
.SpaceAfter = n_SpaceAfter
.LineSpacingRule = n_LineSpacingRule
.LineSpacing = n_LineSpacing
End With
End If
End Sub

Public Function fConcordance()
fConcordance = 0
If Selection.Start = Selection.End Then
Beep
Exit Function
End If
Selection.Copy
fConcordance = fExecute("Concordance#1#")
End Function


Public Function fGetPlaceable(pOffset$)
Dim i_Result
Dim fPlaceable
On Error GoTo -1: On Error GoTo eGetPlaceable
Application.ScreenUpdating = False
b_SmartCutPaste = Options.SmartCutPaste
Options.SmartCutPaste = False

b_ReplaceSelection = Options.ReplaceSelection
Options.ReplaceSelection = True

i_Result = fExecute("GetPlaceable#" + pOffset$ + "#")

If i_Result < 0 Then
nStart = Selection.Start

If i_Result = -1 Then
Rem 1st paste doesn't keep formatting. Don't know why.
Selection.Paste
Selection.Start = nStart
Selection.Paste
Else
Selection.InsertFile _
FileName:=Options.DefaultFilePath(wdTempFilePath) & "\$xfer.rtf", _
ConfirmConversions:=False

Rem magic old command which preserves box formattting
WordBasic.WW6_EditClear -1
End If

Selection.Start = nStart
End If

fPlaceable = i_Result

eGetPlaceable:
On Error GoTo -1: On Error GoTo 0
Options.SmartCutPaste = b_SmartCutPaste
Application.ScreenUpdating = True
Options.ReplaceSelection = b_ReplaceSelection
End Function


Public Function fGetTerm(pOffset$)
b_ReplaceSelection = Options.ReplaceSelection
Options.ReplaceSelection = True

Selection.EscapeKey

If fExecute("GetTerm#" + pOffset$ + "#") = -1 Then
Selection.TypeText "j"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.CopyFormat
Selection.Delete

n_Start = Selection.Start
Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=Selection.Start - n_Start, Extend:=wdExtend

Selection.PasteFormat
fGetTerm = -1
End If
Options.ReplaceSelection = b_ReplaceSelection
System.Cursor = wdCursorNormal
End Function

Public Sub sSetPane(pAction)
i_RC = Abs(pAction) Mod 1000 - (Abs(pAction) Mod 100)
If i_RC >= 100 Then
b_Splitted = False
If i_RC >= 300 Then
If ActiveWindow.View.SplitSpecial <> wdPaneEndnotes Then
ActiveWindow.View.SplitSpecial = wdPaneEndnotes
b_Splitted = True
End If
Else
If ActiveWindow.View.SplitSpecial <> wdPaneFootnotes Then
ActiveWindow.View.SplitSpecial = wdPaneFootnotes
b_Splitted = True
End If
End If

If i_RC = 100 Or i_RC = 300 Then
If b_Splitted = True Then
ActiveWindow.ActivePane.Next.Activate
End If
Else
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdMove
End If
b_HasFootnotes = True
Else
b_HasFootnotes = False
ActiveWindow.SplitVertical = 0
End If
End Sub

Private Function fGetString$(pCommand$)
Dim InitString As String
InitString$ = fGetInitString$()

aVersion = fEnsureWorkbench()

If aVersion = 0 Then
Exit Function
ElseIf aVersion <= 3 Then
Dim Buffer As String * 4096
Dim h_Atom As Long
Dim h_Window As Long

h_Window = FindWindowA("TW4Win2Class", vbNullString)

h_Atom = GlobalAddAtomA(InitString$ + "#" + pCommand$)
h_Atom = SendMessageA(h_Window, WM_USER + 2, h_Atom, 0)
n_Len = GlobalGetAtomNameA(h_Atom, Buffer, 4096)
GlobalDeleteAtom (h_Atom)

fGetString$ = Left$(Buffer, n_Len)
Else
fGetString$ = oWorkbench.ExecuteWordCommandString(InitString$ + "#" + pCommand$)
End If
End Function

Public Function fExecute(pCommand$)
Dim InitString As String
InitString$ = fGetInitString$()

aVersion = fEnsureWorkbench()

If aVersion = 0 Then
Exit Function
ElseIf aVersion <= 3 Then
Dim h_Atom As Long
Dim h_Window As Long

h_Window = FindWindowA("TW4Win2Class", vbNullString)

h_Atom = GlobalAddAtomA(InitString$ + "#" + pCommand$)
fExecute = SendMessageA(h_Window, WM_USER + 2, h_Atom, 0)
GlobalDeleteAtom (h_Atom)
Else
fExecute = oWorkbench.ExecuteWordCommandLong(InitString$ + "#" + pCommand$)
End If
End Function

Private Function fGetInitString$()
aVersion$ = Application.VERSION
aVersion$ = Left$(aVersion$, InStr(aVersion$, ".") - 1)
aLanguage$ = WordBasic.[AppInfo$](16)

fGetInitString$ = Str$(VERSION) + "#Word" + aVersion$ + "#" + aLanguage$
End Function

Private Function fEnsureWorkbench()
On Error Resume Next

' check whether WB is still alive
If Not oWorkbench Is Nothing Then
'get version string to test whether TWB responds
aVersion$ = oWorkbench.VERSION

If Err.Number <> 0 Then
Set oWorkbench = Nothing
End If
End If

' try to launch WB if it does not exist
If oWorkbench Is Nothing Then
Set oWorkbench = GetObject(, "TW4Win.Application")
End If

If oWorkbench Is Nothing Then
MsgBox "Trados Translator's Workbench is not running.", _
vbExclamation + vbOKOnly, "TRADOS Translator's Workbench"
fEnsureWorkbench = 0
Else
aVersion$ = oWorkbench.VERSION
fEnsureWorkbench = Val(Left$(aVersion$, InStr(aVersion$, ".") - 1))
End If
End Function

Public Sub sPushFindSettings()
With Selection.Find
FindText$ = .Text
b_MatchWholeWord = .MatchWholeWord
b_Forward = .Forward
b_MatchCase = .MatchCase
b_MatchWildCards = .MatchWildcards
b_MatchSoundsLike = .MatchSoundsLike
b_MatchAllWordForms = .MatchAllWordForms
End With
End Sub

Public Sub sPopFindSettings()
With Selection.Find
.Text = FindText$
.MatchWholeWord = b_MatchWholeWord
.Forward = b_Forward
.MatchCase = b_MatchCase
.MatchWildcards = b_MatchWildCards
.MatchSoundsLike = b_MatchSoundsLike
.MatchAllWordForms = b_MatchAllWordForms
End With
End Sub

Public Sub sGotoIndexBegin()
Selection.End = ActiveDocument.Bookmarks("tw4winUpto").Range.End
Selection.Find.Execute FindText:=Chr(34)
Selection.Start = Selection.Start + 1
Selection.Collapse
End Sub


Public Sub sAddTagStyles()
Dim aStyles
Dim aExternalFound
Dim aInternalFound
Dim aStyle$
WordBasic.StartOfDocument
WordBasic.CharRight 1, 1
Selection.CopyFormat
WordBasic.ResetChar
WordBasic.FormatStyle Name:="tw4winNone", Type:=1, _
AddToTemplate:=0, Define:=1

aStyles = WordBasic.CountStyles()

aExternalFound = 0
aInternalFound = 0
While aStyles
aStyle$ = WordBasic.[StyleName$](aStyles)
If aStyle$ = "tw4winExternal" Then
aExternalFound = -1
ElseIf aStyle$ = "tw4winInternal" Then
aInternalFound = -1
End If
If aExternalFound < 0 And aInternalFound < 0 Then
aStyles = 0
Else
aStyles = aStyles - 1
End If
Wend

If aExternalFound = 0 Then
WordBasic.FormatStyle Name:="tw4winExternal", _
Type:=1, AddToTemplate:=0, Define:=1
WordBasic.FormatDefineStyleFont Font:="Courier New", Color:=15
End If

If aInternalFound = 0 Then
WordBasic.FormatStyle Name:="tw4winInternal", _
Type:=1, AddToTemplate:=0, Define:=1
WordBasic.FormatDefineStyleFont Font:="Courier New", Color:=6
End If

Selection.PasteFormat
WordBasic.CharLeft 1, 0
End Sub

Public Function fSaveClipboardContents(sClip)
Rem code kindly provided by coolejo to save clipboard contents
Dim ClipboardData As DataObject
On Error Resume Next
Set ClipboardData = New DataObject
ClipboardData.GetFromClipboard
sClip = ClipboardData.GetText
Rem End code by coolejo to save clipboard contents
End Function

Public Function fRestoreClipboardContents(sClip)
Rem code kindly provided by coolejo to save clipboard contents
Set ClipboardData = New DataObject
ClipboardData.SetText sClip
ClipboardData.PutInClipboard
Rem End code kindly provided by coolejo to save clipboard contents
End Function


Public Function fFind(pFind$, pDirection, pPattern, pWrap, pFormat)
fFind = 0
On Error GoTo -1: On Error GoTo eFind

If pFormat = 0 Then
WordBasic.EditFindClearFormatting
WordBasic.EditReplaceClearFormatting
End If

WordBasic.EditFind Find:=pFind$, Replace:="", _
Direction:=pDirection, Wrap:=pWrap, Format:=pFormat, _
PatternMatch:=pPattern, SoundsLike:=0, _
MatchCase:=0, WholeWord:=0

fFind = WordBasic.EditFindFound()
eFind:
On Error GoTo -1: On Error GoTo 0
End Function


Public Function fReplace(pOne, pFind$, pReplace$, _
pDirection, pPattern, pWrap)
fReplace = 0
On Error GoTo -1: On Error GoTo eReplace

WordBasic.EditFindClearFormatting
WordBasic.EditReplaceClearFormatting

If pOne Then
WordBasic.EditReplace Find:=pFind$, Replace:=pReplace$, _
Direction:=pDirection, Wrap:=pWrap, Format:=0, _
PatternMatch:=pPattern, SoundsLike:=0, _
MatchCase:=0, WholeWord:=0, _
ReplaceOne:=1
Else
WordBasic.EditReplace Find:=pFind$, Replace:=pReplace$, _
Direction:=pDirection, Wrap:=pWrap, Format:=0, _
PatternMatch:=pPattern, SoundsLike:=0, _
MatchCase:=0, WholeWord:=0, _
ReplaceAll:=1
End If

fReplace = WordBasic.EditFindFound()
eReplace:
On Error GoTo -1: On Error GoTo 0
End Function


Public Function fSetCloseOpenGet(Optional bToFuzzy As Boolean = False)
b_ShowHidden = ActiveWindow.View.ShowHiddenText
ActiveWindow.View.ShowHiddenText = True
b_ReplaceSelection = Options.ReplaceSelection
Options.ReplaceSelection = True

If b_HasFootnotes Then
n_FootnoteSegment = nGetNextFootnote(s_FNProcessed)
If n_FootnoteSegment > 0 Then
i_Result = fSubSegment(n_FootnoteSegment)
GoTo eSetCloseOpenGet
Else
s_FNProcessed = ""
End If
End If

Dim n_Flag As Integer
n_Flag = 1

If bToFuzzy Then
i_Result = fRequest("", "SetCloseOpenGet#1#")
n_Flag = n_Flag + 1
Else
i_Result = fRequest("", "SetCloseOpenGet#0#")
End If
If i_Result >= 0 Then
GoTo eSetCloseOpenGet
End If

If Abs(i_Result) Mod 10 = 8 Then
'standalone footnote
ActiveDocument.Bookmarks("tw4winFrom").Delete
ActiveDocument.Bookmarks("tw4winUpto").Delete

i_Result = i_Open(n_Flag)

ElseIf Abs(i_Result) Mod 10 = 9 Then
'no more sentences in current paragraph
i_Result = 1
While i_Result >= 1
If WordBasic.ParaDown(1, 0) = 0 Or fNextTextParagraph() = 0 Then
If n_InNote = 0 Then
i_Result = fExecute("Clear#1#")
GoTo eSetCloseOpenGet
ElseIf n_InNote < 10 Then
'subsegment footnote
i_Result = tw4winMain.fMainSegment()
If i_Result >= 0 Then
GoTo eSetCloseOpenGet
End If

n_FootnoteSegment = nGetNextFootnote(s_FNProcessed)
If n_FootnoteSegment > 0 Then
i_Result = fSubSegment(n_FootnoteSegment)
End If

GoTo eSetCloseOpenGet
ElseIf n_InNote < 100 Then
'standalone footnote
i_Result = fMainSegment()
i_Result = fNextTextParagraph()
Else
'Open in footnote pane without mainsegment
i_Result = fMainSegment()
GoTo eSetCloseOpenGet
End If
End If

i_Result = i_Open(n_Flag)
Wend
End If

eSetCloseOpenGet:
fSetCloseOpenGet = i_Result
ActiveWindow.View.ShowHiddenText = b_ShowHidden
Options.ReplaceSelection = b_ReplaceSelection
End Function

Public Function i_Open(n_Flag As Integer)
If bCheckStatus(True) = False Then
Selection.Collapse
Exit Function
End If

n_SelInfo = Selection.Information(wdReferenceOfType)

If Selection.StoryType = wdFootnotesStory Or Selection.StoryType = wdEndnotesStory Then
If Selection.StoryType = wdFootnotesStory Then
n_InNote = 101
Else
n_InNote = 102
End If

n_Offset = Selection.Start - fGetNote(n_InNote, Selection.Range).Range.Start

fGetNote(n_InNote, Selection.Range).Reference.Select

ActiveWindow.SplitVertical = 0

Set o_Footnote = fGetNote(n_InNote, Selection.Range)

sOpenFootnoteWindow (n_Offset)
ElseIf n_SelInfo = 1 Or n_SelInfo = 2 Then
n_InNote = 10 + n_SelInfo

Set o_Footnote = fGetNote(n_InNote, ActiveDocument.Range(Selection.Start))

sOpenFootnoteWindow (0)
End If

Select Case n_Flag
Case 0
i_Result = fRequest("open", "Open#0#")
Case 1
i_Result = fRequest("open", "Open#1#")
Case 2
i_Result = fRequest("open", "Open#2#")
End Select

If Abs(i_Result) Mod 100 >= 10 Then
sGotoIndexBegin
End If

i_Open = i_Result
End Function


Public Function nGetNextFootnote(s_processed As String)
nGetNextFootnote = 0

n_Current = Selection.Start

Selection.GoTo What:=wdGoToBookmark, Name:="tw4winFrom"
Selection.MoveDown wdParagraph, 3

n_Footnote = Selection.Start

Selection.MoveDown wdParagraph, 2
n_Upto = Selection.Start

Set o_Current = ActiveDocument.Range(n_Footnote, n_Upto)

Do
o_Current.Start = n_Footnote
o_Current.End = n_Upto

n_Footnote = 0
If o_Current.Footnotes.Count > 0 Then
n_Footnote = o_Current.Footnotes(1).Reference.Start
End If
If o_Current.Endnotes.Count > 0 Then
n_Endnote = o_Current.Endnotes(1).Reference.Start

If n_Endnote < n_Footnote Then
n_Footnote = n_Endnote
End If
End If

If n_Footnote > 0 Then
o_Current.Start = n_Footnote - 3
o_Current.End = n_Footnote

If (Left$(o_Current.Text, 1) = "{" Or Left$(o_Current.Text, 1) = "1") And _
(Right$(o_Current.Text, 1) = ">") Then
If Left$(o_Current.Text, 1) = "{" Then
o_Current.Start = n_Footnote - 2
End If

o_Current.End = n_Footnote - 1

n_SubSegment = Val(o_Current.Text)

If InStr(s_processed, "," & o_Current.Text & ",") = 0 Then
nGetNextFootnote = n_SubSegment
Exit Function
End If
End If

n_Footnote = n_Footnote + 1
End If
Loop While n_Footnote > 0

Selection.Start = n_Current
Selection.Collapse
End Function


Public Function fFindTemplate() As Template
Dim templ As Template

For Each templ In Templates
If LCase(templ.Name) = "trados7.dot" Then
Exit For
End If
Next

Set fFindTemplate = templ
End Function

Function fGetNote(n_Footnote, o_Range As Range) As Object
If n_Footnote Mod 10 = 1 Then
Set fGetNote = o_Range.Footnotes(1)
Else
Set fGetNote = o_Range.Endnotes(1)
End If
o_Range.Select
End Function
 
R

rVo

Dear Nomey,

That's quite a small needle in quite a big haystack you're looking for.
Checked the code quickly, can't find any obvious manipulation of tables in
here. Have you checked the styles of the template? Good chance it's in
there.

Kind Regards,

rVo

Nomey said:
Could anybody tell me where/how a text box with blue or yellow shading,
and grey borders are defined in the following code? I just want to change
the shading color.
Best regards,
Nomey


=========code===========

Dim bParagraphAdded As Boolean
Dim bEndOfDocument As Boolean
Dim FindText$
Dim b_MatchWholeWord As Boolean
Dim b_Forward As Boolean
Dim b_MatchCase As Boolean
Dim b_MatchWildCards As Boolean
Dim b_MatchSoundsLike As Boolean
Dim b_MatchAllWordForms As Boolean

Dim n_MainHeight As Integer
Dim n_MainWidth As Integer
Dim n_MainLeft As Integer
Dim n_MainTop As Integer
Dim s_MainDocument As String
Dim n_CommandBars
Dim b_CommandBarsEnabled(255) As Boolean

Dim o_Footnote As Object
Dim n_InNote As Integer
Dim b_HasFootnotes As Boolean
Dim s_FNProcessed As String
Dim n_FootnoteHighlight As Integer
Dim n_SpaceBefore As Integer
Dim n_SpaceAfter As Integer
Dim n_LineSpacingRule As Integer
Dim n_LineSpacing As Integer

' XP specific
Dim bOldPasteSmartCutPaste As Boolean

Dim TWMessage$(12, 5)

'Dim oWorkbench As TW4Win.Application
Dim oWorkbench As Object

Declare Function FindWindowA Lib "User32" (ByVal Classname As String, _
ByVal WindowTtile As String) As Long
Declare Function SendMessageA Lib "User32" (ByVal Window As Long, _
ByVal Message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GlobalAddAtomA Lib "Kernel32" (ByVal Entry As String) As Long
Declare Function GlobalGetAtomNameA Lib "Kernel32" (ByVal Atom As Long, _
ByVal Buffer As String, ByVal Length As Long) As Long
Declare Sub GlobalDeleteAtom Lib "Kernel32" (ByVal Atom As Long)

Const WM_USER = 1024
Const VERSION = 600
Const ONEBOOKMARK = 0
Const ALREADYOPEN = 1
Const NOTHINGOPEN = 2
Const REVISIONON = 3
Const OPENFOOTNOTE = 4
Const PLACEDFNNOTEFOUND = 5
Public Const PROTECTED = 6
Public Const DONTCLOSEFNWINDOW = 7
Public Const PROTECTIONON = 8
Public Const PROTECTIONOFF = 9
Public Const SPELLCHECKCOMPLETE = 10
Public Const TUSTILLOPEN = 11

Dim EventHandler As New tw4winEventHandler
Dim FNWindowEventHandler As New tw4winFNWindowEventHandler

Public Sub Main()
End Sub
' XP specific method
Private Function bGetXPShowWindowsInTaskbar() As Boolean
bGetXPShowWindowsInTaskbar = Application.ShowWindowsInTaskbar
End Function
' generic method
Private Function bSDI() As Boolean
Dim iAppVersion As Long
iAppVersion = Val(Application.VERSION)

If iAppVersion < 9 Then
bSDI = False ' MDI mode for Word 97 and earlier
ElseIf iAppVersion = 9 Then
bSDI = True ' SDI mode for Word 2000
ElseIf iAppVersion >= 10 Then
bSDI = bGetXPShowWindowsInTaskbar() ' read XP's flag
End If
End Function

Private Sub DisableXPPasteSmartStyleBehavior(bDisable As Boolean)
With Application.Options
If bDisable Then
bOldPasteSmartCutPaste = .PasteSmartCutPaste
.PasteSmartCutPaste = False
Else ' restore
.PasteSmartCutPaste = bOldPasteSmartCutPaste
End If
End With
End Sub
' generic method
Private Sub DisablePasteSmartStyleBehavior(bDisable As Boolean)
If Val(Application.VERSION) >= 10 Then
DisableXPPasteSmartStyleBehavior bDisable
End If
End Sub
Private Function bWithinTable(rRange As Range) As Boolean
bWithinTable = False
For i = 1 To ActiveDocument.Tables.Count
With ActiveDocument.Tables(i)
If rRange.Start >= .Range.Start _
And rRange.End <= .Range.End Then
bWithinTable = True
Exit Function
End If
End With
Next i
End Function

Public Function fGetMessage$(n_ID)
If TWMessage$(0, 0) = "" Then
TWMessage$(0, 0) = "Bookmark 'tw4winFrom' xor 'tw4winUpto' " _
& "exists: Use 'Fix document' from the Trados menu!"
TWMessage$(1, 0) = "Translation Unit seems to be open: " _
& "close it before opening a new one!"
TWMessage$(2, 0) = "No Translation Unit seems to be open!"
TWMessage$(3, 0) = "You cannot use Workbench while Track Changes is on." _
+ Chr(13) + "* In Word 97 and 2000, deactivate 'Track changes
while editing' under Tools/Track Changes/Highlight Changes..." _
+ Chr(13) + "* In Word XP, deactivate 'Track changes' under Tools."
TWMessage$(4, 0) = "You have to close footnote segment before continuing with main segment."
TWMessage$(5, 0) = "Couldn't find already placed footnote in target segment."
TWMessage$(6, 0) = "Protected tag!"
TWMessage$(7, 0) = "Use Alt+0 to close footnote window and to return to main segment."
TWMessage$(8, 0) = "Tag Protection ON"
TWMessage$(9, 0) = "Tag Protection OFF"
TWMessage$(10, 0) = "The spelling and grammar check is complete."
TWMessage$(11, 0) = "This command is not available because a translation unit is open."

TWMessage$(0, 1) = "Textmarke 'tw4winFrom' xor 'tw4winUpto' " _
& "existiert: Verwenden Sie 'Dokument reparieren' vom Menu Trados!"
TWMessage$(1, 1) = "Vermutlich ist noch eine ÜE geöffnet. " _
& "Schließen Sie sie, bevor Sie fortfahren."
TWMessage$(2, 1) = "Es ist anscheinend keine Übersetzungseinheit geöffnet."
TWMessage$(3, 1) = "Sie können mit Workbench nicht arbeiten,
solange die Funktion 'Änderungen nachverfolgen' aktiv ist." + Chr(13) _
+ Chr(13) + "* In Word 97 und 2000 deaktivieren Sie die Option
'Änderungen während der Bearbeitung markieren' unter Extras/Änderungen
verfolgen/Änderungen hervorheben..." _
+ Chr(13) + "* In Word XP deaktivieren Sie die Option 'Änderungen nachverfolgen' unter Extras."
TWMessage$(4, 1) = "Schließen Sie das Fußnotensegment, bevor Sie
mit dem Hauptsegment fortfahren."
TWMessage$(5, 1) = "Die bereits plazierte Fußnote konnte im
Zielsegment nicht gefunden werden."
TWMessage$(6, 1) = "Geschütztes Tag."
TWMessage$(7, 1) = "Verwenden Sie Alt+0, um das Fußnoten-Fenster
zu schließen und zum Hauptsegment zurückzukehren."
TWMessage$(8, 1) = "Tag-Schutz an!"
TWMessage$(9, 1) = "Tag-Schutz aus!"
TWMessage$(10, 1) = "Die Rechtschreib- und Grammatikprüfung ist abgeschlossen."
TWMessage$(11, 1) = "Dieser Befehl ist nicht verfügbar, weil eine
Übersetzungseinheit offen ist."
TWMessage$(0, 2) = "Signet 'tw4winFrom' xor 'tw4winUpto' " _
& "existe: Utiliser 'Rétablir document' de menu Trados !"
TWMessage$(1, 2) = "Unité de traduction semble ouverte : " _
& "fermer UT avant d'en ouvrir une autre !"
TWMessage$(2, 2) = "Aucune unité de traduction semble être ouverte !"
TWMessage$(3, 2) = "Vous ne pouvez pas utiliser le Workbench
lorsque le mode Suivi des Modifications est activé." _
+ Chr(13) + "* Dans Word 97 et 2000, désactivez l'option
'Signaler les modifications lors de l'édition' sous Outils/Suivi des
Modifications/Afficher les Modifications..." _
+ Chr(13) + "* Dans Word XP, désactivez l'option 'Suivi des modifications' sous Outils."
TWMessage$(4, 2) = "Fermez le segment de la note en bas de page
avant de terminer le segment principal."
TWMessage$(5, 2) = "La note en bas de page déjà placée ne peut
être trouvée dans le segment cible."
TWMessage$(6, 2) = "Balise protégée !"
TWMessage$(7, 2) = "Alt+0 pour fermer la fenêtre de la note en bas
de page et pour retourner au segment principal."
TWMessage$(8, 2) = "Balises protégées!"
TWMessage$(9, 2) = "Balises non protégées!"
TWMessage$(10, 2) = "Vérification grammaticale et orthographique terminée."
TWMessage$(11, 2) = "Cette commande n'est pas disponible parce
qu'une unité de traduction est ouverte."
TWMessage$(0, 3) = "ƒuƒbƒNƒ}[ƒN 'tw4winFrom' xor 'tw4winUpto' " _
& "‚ª‚ ‚è‚Ü‚·B: [trados]ƒƒjƒ…[‚©‚ç'•¶‘‚ÌC³'‚ð‚µ‚Ä‚­‚¾‚³‚¢! "
TWMessage$(1, 3) = "–|–ó’PˆÊ‚ªŠJ‚¢‚Ä‚¢‚Ü‚·B " _
& "V‚µ‚¢‚Ì‚ðŠJ‚­‘O‚ɕ‚¶‚Ä‚­‚¾‚³‚¢!"
TWMessage$(2, 3) = "–|–ó’PˆÊ‚ªŠJ‚©‚ê‚Ä‚¢‚Ü‚¹‚ñ!"
TWMessage$(3, 3) = "•ÏX—š—ð‚Ì•\Ž¦‚ªƒIƒ“‚Ì‚Æ‚«‚Í Workbench
‚ðŽg‚¦‚Ü‚¹‚ñB" _
+ Chr(13) + "
‘±‚¯‚é‚É‚Í[ƒc[ƒ‹]ƒƒjƒ…[‚Ì[•ÏX—š—ð‚Ìì¬]‚Ì[•ÏX‰ÓŠ‚Ì•\Ž¦]‚Å" _
+ Chr(13) + "[•ÒW’†‚É•ÏX‰ÓŠ‚ð‹L˜^‚·‚é]‚ðƒIƒt‚É‚µ‚Ä‚­‚¾‚³‚¢B"
TWMessage$(4, 3) = "–{•¶ß‚É‚¤‚‚é‚É•›•¶ß‚ð•Â‚¶‚Ä‚­‚¾‚³‚¢B"
TWMessage$(5, 3) = "–󕶕¶ß‚É‚»‚Ì•›•¶ß‚ªŒ©‚‚©‚è‚Ü‚¹‚ñB"
TWMessage$(6, 3) = "‚±‚̃^ƒO‚̓vƒƒeƒNƒg‚³‚ê‚Ä‚¢‚Ü‚·!"
TWMessage$(7, 3) = "‹r’‚ð•Â‚¶‚Ä–{•¶‚É–ß‚é‚É‚Í Alt+0 ‚ð‰Ÿ‚µ‚Ä‚­‚¾‚³‚¢B"
TWMessage$(8, 3) = "ƒ^ƒOƒvƒƒeƒNƒVƒ‡ƒ“‚ª—LŒø‚É‚È‚Á‚Ä‚¢‚Ü‚·B"
TWMessage$(9, 3) = "ƒ^ƒOƒvƒƒeƒNƒVƒ‡ƒ“‚ª–³Œø‚É‚È‚Á‚Ä‚¢‚Ü‚·B"
TWMessage$(10, 3) = "The spelling and grammar check is complete."
TWMessage$(11, 3) = "–|–ó’PˆÊ‚ªŠJ‚©‚ê‚Ä‚¢‚邽‚ßA‚±‚̃Rƒ}ƒ “ƒh‚ÍŽg—p‚Å‚«‚Ü‚¹‚ñB"

TWMessage$(0, 4) = "El marcador 'tw4winFrom' xor 'tw4winUpto' " _
& "existe: Use la opción 'Arreglar documento' del menú Trados"
TWMessage$(1, 4) = "Parece que hay una unidad de traducción abierta: " _
& "ciérrela antes de abrir una unidad nueva."
TWMessage$(2, 4) = "No parece haber ninguna unidad de traducción abierta."
TWMessage$(3, 4) = "No se puede usar Workbench mientras el modo de
Control de Cambios está activado." _
+ Chr(13) + "* En Word 97 y 2000, desactive Herramientas/Control
de cambios/Aceptar antes de continuar." _
+ Chr(13) + "* En Word XP, desactive Herramientas/Control de cambios."
TWMessage$(4, 4) = "Debe cerrar el segmento de la nota al pie
antes de continuar con el segmento principal."
TWMessage$(5, 4) = "No se ha podido encontrar la nota al pie
colocada en el segmento de destino."
TWMessage$(6, 4) = "Etiqueta protegida."
TWMessage$(7, 4) = "Use Alt+0 para cerrar la ventana de la nota al
pie y volver al segmento principal."
TWMessage$(8, 4) = "Protección de etiquetas desactivada!"
TWMessage$(9, 4) = "Protección de etiquetas activada!"
TWMessage$(10, 4) = "La verificación ortográfica y gramatical ha finalizado."
TWMessage$(11, 4) = "El comando no está disponible porque una
unidad de traducción está abierta."
TWMessage$(0, 5) = "´æÔÚÊéÇ© tw4winFrom ºÍ/»ò tw4winUpto£º " _
& "ÇëʹÓà Trados ²Ëµ¥Éϵġ°ÐÞ¸´Îĵµ¡±ÃüÁî¡£"
TWMessage$(1, 5) = "´æÔÚδ¹Ø±ÕµÄ·­Òëµ¥Ôª£º" _
& "ÇëÏȽ«Æä¹Ø±Õ£¬²ÅÄÜ´ò¿ªÐµķ­Òëµ¥Ôª£¡"
TWMessage$(2, 5) = "ûÓдò¿ªµÄ·­Òëµ¥Ôª£¡"
TWMessage$(3, 5) = "ÐÞ¶©¹¦ÄÜ´ò¿ªÊ±£¬ÎÞ·¨Ê¹Óà Workbench¡£" _
+ Chr(13) + "* ÔÚ Word 97 ºÍ 2000
ÖУ¬Çëµ¥»÷¡°¹¤¾ß¡±£­¡°ÐÞ¶©¡±£­¡°Í»³öÏÔʾÐÞ¶©¡±Í£Óøù¦ÄÜ¡£" _
+ Chr(13) + "* ÔÚ Word 2002 ÖУ¬Çëµ¥»÷¡°¹¤¾ß¡±£­¡°ÐÞ¶©¡±Í£Óøù¦ÄÜ¡£"
TWMessage$(4, 5) = "ÔÚ¼ÌÐø·­ÒëÖ÷¾ä¶Î֮ǰ£¬±ØÐëÏȹرսÅ×¢¾ä¶Î¡£"
TWMessage$(5, 5) = "ÔÚÄ¿±ê¾ä¶ÎÖÐÎÞ·¨ÕÒµ½ÒÑ·ÅÖõĽÅ×¢¡£"
TWMessage$(6, 5) = "Êܱ£»¤µÄ±ê¼Ç£¡"
TWMessage$(7, 5) = "ÇëʹÓà Alt+0 ¹Ø±Õ½Å×¢´°¿Ú£¬·µ»ØÖ÷¾ä¶Î¡£"
TWMessage$(8, 5) = "±ê¼Ç±£»¤´¦ÓÚ´ò¿ª×´Ì¬"
TWMessage$(9, 5) = "±ê¼Ç±£»¤´¦ÓڹرÕ״̬"
TWMessage$(10, 5) = "The spelling and grammar check is complete."
TWMessage$(11, 5) = "This command is not available because a translation unit is open."

End If

nLang = Val(Application.International(wdProductLanguageID))

If nLang = 1031 Or nLang = 2055 Then
n_Language = 1
ElseIf nLang = 1036 Or nLang = 3084 Then
n_Language = 2
ElseIf nLang = 1041 Then
n_Language = 3
ElseIf nLang = 1034 Or nLang = 2058 Then
n_Language = 4
ElseIf nLang = 2052 Then
n_Language = 5
Else
n_Language = 0
End If

msg$ = TWMessage$(n_ID, n_Language)
If msg$ = "" Then
fGetMessage$ = TWMessage$(n_ID, 0)
Else
fGetMessage$ = msg$
End If
End Function

Public Sub sMessage(n_message As Integer, b_beep As Boolean)
StatusBar = fGetMessage$(n_message)

If b_beep = True Then
Beep
End If
End Sub

Public Function fMainSegment()
b_ReplaceSelection = Options.ReplaceSelection
Options.ReplaceSelection = True

If n_InNote > 10 Then
' no main segment exists
a = bCloseFootnoteWindow()
GoTo eMainSegment
End If

If bCloseFootnoteWindow() = False Then
GoTo eMainSegment
End If

If bCheckStatus(False) = False Then
GoTo eMainSegment
End If

fMainSegment = fRequest("current", "MainSegment#0#")

eMainSegment:
Options.ReplaceSelection = b_ReplaceSelection
End Function


Public Function fSubSegment(n_SubSegment)

aClip = tw4winMain.fSaveClipboardContents(sClip)

System.Cursor = wdCursorWait
Application.ScreenUpdating = False

b_ShowHidden = ActiveWindow.View.ShowHiddenText
ActiveWindow.View.ShowHiddenText = True

b_ReplaceSelection = Options.ReplaceSelection
Options.ReplaceSelection = True

If bCheckStatus(False) = False Then
GoTo eSubSegment
End If

Selection.Collapse
ActiveDocument.Bookmarks.Add Name:="tw4winHere"

Selection.Start = ActiveDocument.Bookmarks("tw4winFrom").Range.Start
Selection.Collapse
Selection.MoveDown wdParagraph, 1
n_From = Selection.Start

Selection.Start = ActiveDocument.Bookmarks("tw4winUpto").Range.Start
Selection.Collapse
Selection.MoveUp wdParagraph, 1
n_Upto = Selection.Start

Dim o_Current As Range
Set o_Current = ActiveDocument.Range(n_From, n_Upto)
o_Current.TextRetrievalMode.IncludeHiddenText = True

s_SubSegment = Mid$(Str$(n_SubSegment), 2)
s_Tag = "{" & s_SubSegment & ">"
o_Current.Find.Execute FindText:=s_Tag
o_Current.Select

' Find.Found crashes under Hebrew/Arabic Word
If o_Current.Text = s_Tag Then
Selection.Collapse wdCollapseEnd
n_SelInfo = Selection.Information(wdReferenceOfType)
If n_SelInfo = 1 Or n_SelInfo = 2 Then
' copy source foonote
o_Current.End = n_Upto
Set o_Footnote = fGetNote(n_SelInfo, o_Current)
o_Current.End = o_Footnote.Reference.End + 3
If Right(o_Current.Text, 1) <> "}" Then
o_Current.End = o_Current.End + 1
End If
o_Current.Copy

'replace source foontnote with placeholder
o_Footnote.Reference.Select
If n_SelInfo = 1 Then
Selection.TypeText "fn"
Else
Selection.TypeText "en"
End If

o_Current.Start = o_Current.End
aNumber = o_Current.MoveEnd(wdParagraph, 3)

o_Current.Find.Execute FindText:=s_Tag
If o_Current.Text <> s_Tag Then
' new footnote, copy to target
Selection.GoTo What:=wdGoToBookmark, Name:="tw4winHere"
Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=5, Extend:=wdExtend
Set o_Footnote = fGetNote(n_SelInfo, Selection.Range)
Selection.Collapse
Else
o_Current.End = n_Upto
Set o_Footnote = fGetNote(n_SelInfo, o_Current)
End If
n_InNote = n_SelInfo
s_FNProcessed = s_FNProcessed & "," & s_SubSegment & ","
Else
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
If Selection.Text = "fn" Or Selection.Text = "en" Then
If Selection.Text = "fn" Then
n_SelInfo = 1
Else
n_SelInfo = 2
End If
'already placed footnote
o_Current.Start = Selection.End
aNumber = o_Current.MoveEnd(wdParagraph, 3)

o_Current.Find.Execute FindText:=s_Tag
If o_Current.Text = s_Tag Then
o_Current.End = n_Upto
Set o_Footnote = fGetNote(n_SelInfo, o_Current)

n_InNote = n_SelInfo
s_FNProcessed = s_FNProcessed & "," & s_SubSegment & ","
Else
Selection.Start = ActiveDocument.Bookmarks("tw4winHere").Range.Start
Selection.Collapse
ActiveDocument.Bookmarks("tw4winHere").Delete
sMessage PLACEDFNNOTEFOUND, True
GoTo eSubSegment
End If
End If
End If
End If

Selection.Start = ActiveDocument.Bookmarks("tw4winHere").Range.Start
Selection.Collapse
ActiveDocument.Bookmarks("tw4winHere").Delete

If o_Footnote Is Nothing Then
i_Result = fRequest("current", "SubSegment#" & s_SubSegment & "#")
If Abs(i_Result) Mod 100 >= 10 Then
sGotoIndexBegin
End If
Else
If o_Footnote.Range.Text = "" Then
Beep
Else
ActiveWindow.View.ShowHiddenText = b_ShowHidden
sOpenFootnoteWindow (0)
If fNextTextParagraph() = 0 Then
b_close = bCloseFootnoteWindow()
Beep
Else
i_Result = fRequest("open", "Open#1#")
End If
End If
End If

fSubSegment = i_Result

tw4winMain.fRestoreClipboardContents (sClip)


eSubSegment:
Application.ScreenUpdating = True
System.Cursor = wdCursorNormal

ActiveWindow.View.ShowHiddenText = b_ShowHidden
Options.ReplaceSelection = b_ReplaceSelection
End Function


Private Sub sOpenFootnoteWindow(n_Offset)
Set EventHandler.App = Word.Application

s_MainDocument = ActiveDocument.Name
ActiveWindow.SplitVertical = 0

If bSDI() Then
n_MainHeight = Application.Height
n_MainWidth = Application.Width
n_MainLeft = Application.Left
n_MainTop = Application.Top
Else
n_WordHeight = Application.UsableHeight
n_WordWidth = Application.UsableWidth

Dim o_MainDoc As Document
Set o_MainDoc = ActiveDocument

Dim o_MainWin As Window
Set o_MainWin = o_MainDoc.ActiveWindow

With o_MainWin
n_MainHeight = .Height
n_MainWidth = .Width
n_MainLeft = .Left
n_MainTop = .Top
End With
End If

n_FootnoteHighlight = o_Footnote.Reference.HighlightColorIndex
o_Footnote.Reference.HighlightColorIndex = wdYellow

Dim o_FootnoteDoc As Document

On Error Resume Next
Set o_FootnoteDoc = Documents("TW4Win Footnote.doc")
If o_FootnoteDoc Is Nothing Then
Set o_FootnoteDoc = Documents.Add
sFootnoteDoc$ = Options.DefaultFilePath(wdTempFilePath) + "\TW4Win Footnote.doc"
o_FootnoteDoc.SaveAs FileName:=sFootnoteDoc$, AddToRecentFiles:=False
Else
o_FootnoteDoc.Activate
End If

Dim o_FootnoteWin As Window
Set o_FootnoteWin = Windows(o_FootnoteDoc.Name)

If bSDI() Then
Windows(s_MainDocument).Activate

n_CommandBars = 0
For Each cbar In CommandBars
n_CommandBars = n_CommandBars + 1
b_CommandBarsEnabled(n_CommandBars) = cbar.Enabled
If cbar.Enabled = True Then cbar.Enabled = False
Next

n_Height = n_MainHeight / 3
Application.Height = n_Height
Application.ScreenUpdating = True
Application.ScreenRefresh
Application.ScreenUpdating = False

o_FootnoteDoc.Activate
Application.Move Left:=n_MainLeft, Top:=n_MainTop + n_Height
Application.Resize Width:=n_MainWidth, Height:=n_MainHeight - n_Height
Else
n_NewMainHeight = Application.UsableHeight / 3
With o_MainWin
.Left = 0
.Top = 0
.Height = n_NewMainHeight
.Width = Application.UsableWidth
End With
With o_FootnoteWin
.Left = 0
.Top = n_NewMainHeight + 1
.Height = Application.UsableHeight - n_NewMainHeight
.Width = Application.UsableWidth
End With
End If

ActiveDocument.Range.FormattedText = o_Footnote.Range.FormattedText
ActiveDocument.Range.ParagraphFormat = o_Footnote.Range.ParagraphFormat

Selection.Start = n_Offset
End Sub


Private Function bCloseFootnoteWindow()
Set EventHandler.App = Nothing
Set FNWindowEventHandler.App = Word.Application

On Error Resume Next
n_Offset = 0
Set o_FootnoteDoc = Documents("TW4Win Footnote.doc")
If Not (o_FootnoteDoc Is Nothing) Then
If o_FootnoteDoc = Empty Then
bCloseFootnoteWindow = False
Exit Function
End If
If n_InNote > 0 Then
If ActiveDocument.Bookmarks.Exists("tw4winFrom") <> 0 Or _
ActiveDocument.Bookmarks.Exists("tw4winUpto") <> 0 Then
sMessage OPENFOOTNOTE, True
bCloseFootnoteWindow = False
Exit Function
End If

ActiveWindow.View.ShowHiddenText = True

o_FootnoteDoc.Activate
n_Offset = Selection.Start

o_Footnote.Range.FormattedText = o_FootnoteDoc.Range.FormattedText
Set o_Range = o_Footnote.Range
o_Range.Collapse (wdCollapseEnd)
o_Range.Delete wdCharacter, -1

o_Footnote.Reference.HighlightColorIndex = n_FootnoteHighlight
o_Footnote.Reference.Select
End If

sFootnoteDoc$ = o_FootnoteDoc.FullName
o_FootnoteDoc.Close wdDoNotSaveChanges
Kill sFootnoteDoc$
Set o_Footnote = Nothing
End If

On Error Resume Next
Set o_MainWin = Windows(s_MainDocument)
If Not (o_MainWin Is Nothing) Then
o_MainWin.Activate

If bSDI() Then
Application.Resize Width:=n_MainWidth, Height:=n_MainHeight
Application.ScreenUpdating = True
Application.ScreenRefresh
Application.ScreenUpdating = False
n_CommandBars = 0
For Each cbar In CommandBars
n_CommandBars = n_CommandBars + 1
If b_CommandBarsEnabled(n_CommandBars) = True Then
cbar.Enabled = True
End If
Next
Else
With o_MainWin
.Left = n_MainLeft
.Top = n_MainTop
.Height = n_MainHeight
.Width = n_MainWidth
End With
End If

If n_InNote Mod 10 = 1 Then
ActiveWindow.View.SplitSpecial = wdPaneFootnotes
ElseIf n_InNote Mod 10 = 2 Then
ActiveWindow.View.SplitSpecial = wdPaneEndnotes
End If

If n_InNote < 10 Then
ActiveWindow.ActivePane.Next.Activate
ElseIf n_InNote < 100 Then
ActiveWindow.ActivePane.Next.Activate
Selection.Collapse wdCollapseEnd
Else
Selection.Start = fGetNote(n_InNote,
Selection.Range).Range.Start + n_Offset
End If
End If

Set EventHandler.App = Word.Application
Set FNWindowEventHandler.App = Nothing

n_InNote = 0
bCloseFootnoteWindow = True
End Function


Public Function bCheckStatus(b_Open As Boolean)
bCheckStatus = False

n_Exists = ActiveDocument.Bookmarks.Exists("tw4winFrom") _
+ ActiveDocument.Bookmarks.Exists("tw4winUpto")

If n_Exists = -1 Then
If ActiveDocument.Bookmarks.Exists("tw4winFrom") Then
Selection.GoTo What:=wdGoToBookmark, Name:="tw4winFrom"
Else
Selection.GoTo What:=wdGoToBookmark, Name:="tw4winUpto"
End If
sMessage ONEBOOKMARK, True
Exit Function
End If

If b_Open = True Then
If n_Exists Then
Selection.GoTo What:=wdGoToBookmark, Name:="tw4winFrom"
Selection.MoveDown wdParagraph, 3
sMessage ALREADYOPEN, True
Exit Function
End If
'save selection, because in rtl tables following command moves it?!
'nStart = Selection.Start
'nEnd = Selection.End
ActiveDocument.Bookmarks.Add ("tw4winHere")
bRevisionMarking = ActiveDocument.Content.Information(wdRevisionMarking)
'Selection.End = nEnd
'Selection.Start = nStart
ActiveDocument.Bookmarks("tw4winHere").Select
ActiveDocument.Bookmarks("tw4winHere").Delete
If bRevisionMarking Then
MsgBox fGetMessage$(REVISIONON), vbOKOnly + vbInformation,
"TRADOS Translator's Workbench"
Exit Function
End If
Else
If n_Exists = 0 Then
sMessage NOTHINGOPEN, True
Exit Function
End If
End If

bCheckStatus = True

End Function


Public Function fFindNextNo100()
While 1
If fFindNextNo100Segment() = 0 Then
fFindNextNo100 = 0
If n_InNote = 0 Then
GoTo quit
ElseIf n_InNote < 10 Then
'subsegment footnote
i_Result = tw4winMain.fMainSegment()
GoTo quit
ElseIf n_InNote < 100 Then
'standalone footnote
i_Result = fMainSegment()
Else
'Open in footnote pane without mainsegment
GoTo quit
End If
Else
fFindNextNo100 = 1
n_SelInfo = Selection.Information(wdReferenceOfType)

If n_SelInfo = 1 Or n_SelInfo = 2 Then
n_InNote = 10 + n_SelInfo

Set o_Footnote = fGetNote(n_InNote, ActiveDocument.Range(Selection.Start))

sOpenFootnoteWindow (0)
Else
GoTo quit
End If
End If
Wend

quit:

End Function


Public Function fFindNextNo100Segment()
Dim n_Current As Long

Set o_DocRange = Selection.Range
o_DocRange.Expand (wdStory)

n_EndOfDocument = o_DocRange.End
b_ScreenUpdating = Application.ScreenUpdating
Application.ScreenUpdating = False
b_ShowHidden = ActiveWindow.View.ShowHiddenText
ActiveWindow.View.ShowHiddenText = True

n_UpdateCounter = 1

sPushFindSettings
With Selection.Find
.MatchWholeWord = False
.MatchCase = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Wrap = wdFindStop
End With

Selection.Find.ClearFormatting

fFindNextNo100Segment = 1

While 1
If fNextTextParagraph() = 0 Then
n_Current = Selection.Start
fFindNextNo100Segment = 0
GoTo eFindNextNo100
End If

n_Current = Selection.Start
Selection.Collapse
Selection.Find.Execute FindText:="<0}", Forward:=True
If Selection.Text <> "<0}" Then
GoTo eFindNextNo100
End If
n_EndOfMainSegment = Selection.End

Selection.Start = n_Current
Selection.Find.Execute FindText:="{0>"
n_BeginOfMainSegment = n_EndOfDocument
If Selection.Text = "{0>" Then
n_BeginOfMainSegment = Selection.Start
End If

If n_BeginOfMainSegment = n_EndOfDocument _
Or n_BeginOfMainSegment > n_EndOfMainSegment Then
Selection.Start = n_Current
Selection.Collapse
Selection.Find.Execute FindText:="{0>", Forward:=False
If Selection.Text <> "{0>" Then
Rem tagging error, leave loop
GoTo eFindNextNo100
End If
n_BeginOfMainSegment = Selection.Start
End If

If n_Current < n_BeginOfMainSegment Then
Rem virgin source
GoTo eFindNextNo100
End If

Selection.Collapse
Selection.Find.Execute FindText:="<}", Forward:=True
If Selection.Text <> "<}" Then
Rem tagging error
GoTo eFindNextNo100
End If

Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend

If Val(Selection.Text) < 100 Then
Rem fuzzy match
GoTo eFindNextNo100
End If

Selection.Start = n_EndOfMainSegment
Selection.End = n_EndOfMainSegment + 1

If Selection.Start <> n_EndOfMainSegment Then
'end of table cell marker
Selection.Collapse wdCollapseEnd
End If

If n_UpdateCounter > 10 Then
Application.ScreenUpdating = True
Application.ScreenRefresh
Application.ScreenUpdating = False
n_UpdateCounter = 1
Else
n_UpdateCounter = n_UpdateCounter + 1
End If
Wend


eFindNextNo100:
Selection.Start = n_Current
Selection.Collapse
'Florin: the following line seems to fix Samsa #2767
Selection.Start = n_Current

Application.ScreenUpdating = b_ScreenUpdating
ActiveWindow.View.ShowHiddenText = b_ShowHidden
sPopFindSettings
End Function


Public Function fNextTextParagraph()
fNextTextParagraph = 0

Set o_Range = Selection.Range
o_Range.Expand (wdStory)

o_Range.TextRetrievalMode.IncludeHiddenText = True
o_Range.TextRetrievalMode.IncludeFieldCodes = True
o_Range.Start = Selection.Start

Set o_Char = o_Range.Characters.First
n_End = o_Range.Characters.Last.Start
For i = o_Char.Start To n_End
i_value = Asc(o_Char.Text)
If o_Char.Style = "tw4winExternal" Or o_Char.Style = "tw4winInternal" Then
o_Char.Select
Do
n_SelEnd = Selection.End
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
If n_SelEnd = Selection.End Then
Exit For
End If
If Selection.Style Is Nothing Then
Exit Do
End If
Loop While Selection.Style = "tw4winExternal" Or
Selection.Style = "tw4winInternal"
o_Char.Start = n_SelEnd - 1
o_Char.End = n_SelEnd
ElseIf (i_value > 65 And i_value < 91) Or (i_value > 96) Or _
(i_value = 63 And AscW(o_Char.Text) <> 63) Then
fNextTextParagraph = -1
Exit For
ElseIf i_value = 65 Then
' Check on see also footnotes (RTF help)
' Use Selection instead of o_Char to avoid repagination in XP
Selection.Start = o_Char.Start
Selection.End = Selection.Start
n_Note = Selection.Information(wdReferenceOfType)
If n_Note = 1 Or n_Note = 2 Then
s_Ref = fGetNote(n_Note, ActiveDocument.Range(o_Char.Start)).Reference.Text
If s_Ref <> "A" Then
fNextTextParagraph = -1
Exit For
End If
Else
fNextTextParagraph = -1
Exit For
End If
ElseIf i_value <= 2 Then
If Selection.StoryType <> wdFootnotesStory And _
Selection.StoryType <> wdEndnotesStory Then
fNextTextParagraph = -1
Exit For
End If
ElseIf i_value = 36 Then
' Check on dollar footnotes (RTF help)
' Use Selection instead of o_Char to avoid repagination in XP
Selection.Start = o_Char.Start
Selection.End = Selection.Start
n_Note = Selection.Information(wdReferenceOfType)
If n_Note = 1 Or n_Note = 2 Then
fNextTextParagraph = -1
Exit For
End If
End If
Set o_Char = o_Char.Next
Next i
If i < n_End Then
o_Char.Select
End If
End Function

Public Function fRequest(pMode$, pCommand$)
Dim aLanguage$
Dim ParagraphBookmarks
Dim BookmarkNames(1 To 50) As String
Dim CurrentParagraph As Range

Set o_DocRange = Selection.Range
o_DocRange.Expand (wdStory)

Dim bOldPasteSmartStyleBehaviour As Boolean
' disable XP's smart cut&paste options
DisablePasteSmartStyleBehavior True

b_ShowHidden = ActiveWindow.View.ShowHiddenText
ActiveWindow.View.ShowHiddenText = True
With Options
b_SmartCutPaste = .SmartCutPaste
.SmartCutPaste = False
b_ReplaceSelection = .ReplaceSelection
.ReplaceSelection = True
b_TabIndentKey = .TabIndentKey
.TabIndentKey = False
End With

i_Result = 0

If Selection.StoryType = wdTextFrameStory Then
' on Word XP, the below Selection.EscapeKey will reset Start = End = 0 instead
' of collapsing to the current Start/End.
Selection.End = Selection.Start
Else
Selection.EscapeKey
Selection.Collapse
End If

If Selection.StoryType = wdFootnotesStory Or Selection.StoryType = wdEndnotesStory Then
ActiveWindow.ActivePane.Next.Activate
End If

aLanguage$ = WordBasic.AppInfo$(16)

Dim b_Open As Boolean
If pMode$ = "open" Then
b_Open = True
bParagraphAdded = False
Else
b_Open = False
End If

If bCheckStatus(b_Open) = False Then
GoTo eRequest
End If

Rem asign current paragraph to a range
If pMode$ = "open" Then
Set CurrentParagraph = Selection.PARAGRAPHS(1).Range

If n_InNote = 0 Then
With CurrentParagraph.ParagraphFormat
n_SpaceBefore = .SpaceBefore
n_SpaceAfter = .SpaceAfter
n_LineSpacing = .LineSpacing
n_LineSpacingRule = .LineSpacingRule
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = 0
End With
End If

bEndOfDocument = False
Else
Set CurrentParagraph = o_DocRange.Duplicate
CurrentParagraph.Start = o_DocRange.Bookmarks("tw4winFrom").Range.Start
CurrentParagraph.End = o_DocRange.Bookmarks("tw4winUpto").Range.End
End If

CurrentParagraph.TextRetrievalMode.IncludeHiddenText = True
CurrentParagraph.TextRetrievalMode.IncludeFieldCodes = True

Rem assign next paragraph (for file inserts)
If CurrentParagraph.End = o_DocRange.End Then
CurrentParagraph.InsertParagraphAfter
CurrentParagraph.End = CurrentParagraph.End - 1
CurrentParagraph.Characters.Last.Font.Reset
bEndOfDocument = True
End If

Rem if in field leave it
If pMode$ = "open" Or pMode$ = "current" Then
For i = 1 To CurrentParagraph.Fields.Count
Set o_Field = CurrentParagraph.Fields(i)

nStart = o_Field.Code.Start
If o_Field.Kind = wdFieldKindHot Or o_Field.Kind = wdFieldKindWarm Then
nEnd = CurrentParagraph.Fields(i).Result.End
Else
nEnd = CurrentParagraph.Fields(i).Code.End
End If

If nStart <= Selection.Start And nEnd >= Selection.End Then
Selection.Start = nStart - 1
Selection.End = Selection.Start
Exit For
End If
Next i
Else
Selection.Start = o_DocRange.Bookmarks("tw4winFrom").Range.Start
Selection.Collapse
Selection.MoveDown wdParagraph, 3
If Selection.Text = "<" And Selection.Style = "tw4winMark" Then
Selection.MoveDown wdParagraph, 1
End If
End If

'Check on missing paragraph mark (table cells)
'save selection, because in rtl tables following commands move it?!

'nStart = Selection.Start
'nEnd = Selection.End
ActiveDocument.Bookmarks.Add ("tw4winHere")

Set o_Char = CurrentParagraph.Characters.Last.Next
bTableWithoutPar = Asc(Right$(CurrentParagraph.Text, 1)) = 7

Dim bAddParagraph As Boolean
bAddParagraph = bTableWithoutPar
If Not bAddParagraph And ActiveDocument.Tables.Count <> 0 Then
' Use Selection to avoid repagination in Word XP
Selection.Start = o_Char.Start - 1
Selection.End = Selection.Start
If Not Selection.Information(wdWithInTable) Then
Selection.Start = o_Char.Start
Selection.End = Selection.Start
If Selection.Information(wdWithInTable) Then
bAddParagraph = True
End If
End If
End If

ActiveDocument.Bookmarks("tw4winHere").Select
ActiveDocument.Bookmarks("tw4winHere").Delete
'Selection.End = nEnd
'Selection.Start = nStart

Rem save bookmarks
Set ParagraphBookmarks = CurrentParagraph.Bookmarks
bShowHidden = ParagraphBookmarks.ShowHidden
ParagraphBookmarks.ShowHidden = True
BookmarkCount = ParagraphBookmarks.Count
If BookmarkCount > 50 Then
BookmarkCount = 50
End If
For i = BookmarkCount To 1 Step -1
If Left$(ParagraphBookmarks(i).Name, 6) <> "tw4win" Then
BookmarkNames(i) = ParagraphBookmarks(i).Name
o_DocRange.Bookmarks(ParagraphBookmarks(i)).Delete
End If
Next i

Rem insert current marker
n_char = Asc(Selection.Text)
If n_char = 13 Or n_char = 10 Then
Selection.TypeText Chr(30) & "{}" & Chr(30)
Else
Selection.CopyFormat
Selection.TypeText Chr(30) & "{}" & Chr(30)
Selection.MoveLeft Unit:=wdCharacter, Count:=4, Extend:=wdExtend
Selection.PasteFormat
End If

Rem Word 8.0 without SR1 doesn't copy leading hidden text
Rem unhide first char if it's our start segment marker
If Left$(CurrentParagraph.Text, 3) = "{0>" Then
Set o_First = o_DocRange.Duplicate
o_First.Start = CurrentParagraph.Start
o_First.End = CurrentParagraph.Start + 1
o_First.Font.Hidden = 0
Else
Set o_First = Nothing
End If

Rem insert paragraph if necessary and copy to clipboard
If bAddParagraph Then
Selection.Start = CurrentParagraph.End - 1
Selection.Collapse
If bTableWithoutPar Then
Selection.TypeParagraph
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Reset
Else
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Paste
End If
CurrentParagraph.End = CurrentParagraph.End - 1
CurrentParagraph.Copy
CurrentParagraph.End = CurrentParagraph.End - 1
bParagraphAdded = True
Else
CurrentParagraph.Copy
End If

'reset first char
If Not (o_First Is Nothing) Then
o_First.Font.Hidden = 1
End If

'Check Bidi alignment
If Not (b_Open) Then
BidiTest = wdReadingOrderLtr
If Not (BidiTest = Empty) Then
tw4winBidiAlignment.Check CurrentParagraph
End If
End If


'start processing in Workbench
i_Result = fExecute(pCommand$)
If i_Result < 0 Then
If i_Result <= -10000 Then
'no pasting
i_Result = i_Result + 10000
ElseIf i_Result <= -1000 Then
'RTF text contains fields which are not translated via clipboard xfer
i_Result = i_Result + 1000
n_LeftIndent = CurrentParagraph.ParagraphFormat.LeftIndent
Selection.Start = CurrentParagraph.End
Selection.Collapse
Selection.TypeParagraph

'save selection, because in rtl tables strange things happen to it
ActiveDocument.Bookmarks.Add ("tw4winHere")

b_confirm = Options.ConfirmConversions
CurrentParagraph.InsertFile _
FileName:=Options.DefaultFilePath(wdTempFilePath) & "\$xfer.rtf", _
ConfirmConversions:=False
Options.ConfirmConversions = b_confirm
'Kill Options.DefaultFilePath(wdTempFilePath) & "\$xfer.rtf"

'restore selection position
Set o_Bookmark = ActiveDocument.Bookmarks("tw4winHere")
Selection.End = o_Bookmark.Range.End
Selection.Start = o_Bookmark.Range.Start
o_Bookmark.Delete

Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Delete
CurrentParagraph.End = Selection.End
CurrentParagraph.ParagraphFormat.LeftIndent = n_LeftIndent
Else
CurrentParagraph.Paste
' circumvent bug in Word XP (during Paste, CurrentParagraph's ..Range
' is not adjusted correctly if at end of document/story within text boxes)
If CurrentParagraph.StoryType = wdTextFrameStory And bEndOfDocument Then
CurrentParagraph.End = o_DocRange.End
End If
End If

If (pMode$ = "close" Or pMode$ = "open" Or Abs(i_Result) Mod 10 = 9) And _
(bAddParagraph Or bParagraphAdded) Then
If bAddParagraph Then
Selection.Start = CurrentParagraph.End + 1
Else
Selection.Start = CurrentParagraph.End
End If

Selection.TypeBackspace
End If
ElseIf bAddParagraph Then
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
Selection.TypeBackspace
End If

Rem replace current mark
bMarkerDeleted = False
Selection.Start = CurrentParagraph.Start
Selection.Collapse
Selection.Find.ClearFormatting
sPushFindSettings
Selection.Find.MatchWildcards = False
Selection.Find.Forward = True
Selection.Find.Execute FindText:=Chr(30) & "{}" & Chr(30)
If Selection.Text = Chr(30) & "{}" & Chr(30) Then
Selection.Delete
bMarkerDeleted = True
End If
sPopFindSettings

bOpen = False
If i_Result > -1 Then
If pMode$ <> "open" Then
bOpen = True
Else
sRestoreSpacing CurrentParagraph.ParagraphFormat
End If
Else
If pMode$ = "close" Or Abs(i_Result) Mod 10 = 9 Then
sRestoreSpacing CurrentParagraph.ParagraphFormat

If o_DocRange.Bookmarks.Exists("tw4winFrom") Then
o_DocRange.Bookmarks("tw4winFrom").Delete
End If
If o_DocRange.Bookmarks.Exists("tw4winUpto") Then
o_DocRange.Bookmarks("tw4winUpto").Delete
End If

bParagraphAdded = False

If bEndOfDocument = True Then
aEnd = Selection.PARAGRAPHS(1).Range.End
Set o_Range = o_DocRange.Duplicate
o_Range.Start = aEnd - 1
o_Range.End = aEnd
o_Range.Delete
bEndOfDocument = False
End If

If n_InNote = 0 Then
s_FNProcessed = ""
End If
Else
bOpen = True
End If
End If

'set tw4win bookmarks
If bOpen = True Then
'ensure the tw4win fields are visible
If bMarkerDeleted = True Then
n_Current = Selection.Start
Selection.MoveUp Unit:=wdParagraph, Count:=3, Extend:=wdMove
Selection.Start = n_Current
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdMove
Selection.End = n_Current
End If
nStart = CurrentParagraph.Start
nEnd = CurrentParagraph.End
Set o_Range = o_DocRange.Duplicate
o_Range.Start = nStart
o_Range.End = nStart
o_DocRange.Bookmarks.Add Name:="tw4winFrom", Range:=o_Range
o_Range.Start = nEnd
o_Range.End = nEnd
o_DocRange.Bookmarks.Add Name:="tw4winUpto", Range:=o_Range

If i_Result < 0 Then
sSetPane (i_Result)
End If
End If

Rem reinsert bookmarks
For i = 1 To BookmarkCount
mark$ = BookmarkNames(i)
If Len(mark$) > 0 And Left$(BookmarkNames(i), 6) <> "tw4win" Then
ParagraphBookmarks.Add Name:=BookmarkNames(i)
End If
Next i
ParagraphBookmarks.ShowHidden = bShowHidden

eRequest:
On Error GoTo -1: On Error GoTo 0

ActiveWindow.View.ShowHiddenText = b_ShowHidden
Options.SmartCutPaste = b_SmartCutPaste
Options.ReplaceSelection = b_ReplaceSelection
Options.TabIndentKey = b_TabIndentKey
DisablePasteSmartStyleBehavior False

fRequest = i_Result
End Function

Private Sub sRestoreSpacing(o_Format As ParagraphFormat)
If n_InNote = 0 Then
On Error Resume Next
With o_Format
.SpaceBefore = n_SpaceBefore
.SpaceAfter = n_SpaceAfter
.LineSpacingRule = n_LineSpacingRule
.LineSpacing = n_LineSpacing
End With
End If
End Sub

Public Function fConcordance()
fConcordance = 0
If Selection.Start = Selection.End Then
Beep
Exit Function
End If
Selection.Copy
fConcordance = fExecute("Concordance#1#")
End Function


Public Function fGetPlaceable(pOffset$)
Dim i_Result
Dim fPlaceable
On Error GoTo -1: On Error GoTo eGetPlaceable
Application.ScreenUpdating = False
b_SmartCutPaste = Options.SmartCutPaste
Options.SmartCutPaste = False

b_ReplaceSelection = Options.ReplaceSelection
Options.ReplaceSelection = True

i_Result = fExecute("GetPlaceable#" + pOffset$ + "#")

If i_Result < 0 Then
nStart = Selection.Start

If i_Result = -1 Then
Rem 1st paste doesn't keep formatting. Don't know why.
Selection.Paste
Selection.Start = nStart
Selection.Paste
Else
Selection.InsertFile _
FileName:=Options.DefaultFilePath(wdTempFilePath) & "\$xfer.rtf", _
ConfirmConversions:=False

Rem magic old command which preserves box formattting
WordBasic.WW6_EditClear -1
End If

Selection.Start = nStart
End If

fPlaceable = i_Result

eGetPlaceable:
On Error GoTo -1: On Error GoTo 0
Options.SmartCutPaste = b_SmartCutPaste
Application.ScreenUpdating = True
Options.ReplaceSelection = b_ReplaceSelection
End Function


Public Function fGetTerm(pOffset$)
b_ReplaceSelection = Options.ReplaceSelection
Options.ReplaceSelection = True

Selection.EscapeKey

If fExecute("GetTerm#" + pOffset$ + "#") = -1 Then
Selection.TypeText "j"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.CopyFormat
Selection.Delete

n_Start = Selection.Start
Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=Selection.Start - n_Start, Extend:=wdExtend

Selection.PasteFormat
fGetTerm = -1
End If
Options.ReplaceSelection = b_ReplaceSelection
System.Cursor = wdCursorNormal
End Function

Public Sub sSetPane(pAction)
i_RC = Abs(pAction) Mod 1000 - (Abs(pAction) Mod 100)
If i_RC >= 100 Then
b_Splitted = False
If i_RC >= 300 Then
If ActiveWindow.View.SplitSpecial <> wdPaneEndnotes Then
ActiveWindow.View.SplitSpecial = wdPaneEndnotes
b_Splitted = True
End If
Else
If ActiveWindow.View.SplitSpecial <> wdPaneFootnotes Then
ActiveWindow.View.SplitSpecial = wdPaneFootnotes
b_Splitted = True
End If
End If

If i_RC = 100 Or i_RC = 300 Then
If b_Splitted = True Then
ActiveWindow.ActivePane.Next.Activate
End If
Else
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdMove
End If
b_HasFootnotes = True
Else
b_HasFootnotes = False
ActiveWindow.SplitVertical = 0
End If
End Sub

Private Function fGetString$(pCommand$)
Dim InitString As String
InitString$ = fGetInitString$()

aVersion = fEnsureWorkbench()

If aVersion = 0 Then
Exit Function
ElseIf aVersion <= 3 Then
Dim Buffer As String * 4096
Dim h_Atom As Long
Dim h_Window As Long

h_Window = FindWindowA("TW4Win2Class", vbNullString)

h_Atom = GlobalAddAtomA(InitString$ + "#" + pCommand$)
h_Atom = SendMessageA(h_Window, WM_USER + 2, h_Atom, 0)
n_Len = GlobalGetAtomNameA(h_Atom, Buffer, 4096)
GlobalDeleteAtom (h_Atom)

fGetString$ = Left$(Buffer, n_Len)
Else
fGetString$ = oWorkbench.ExecuteWordCommandString(InitString$ + "#" + pCommand$)
End If
End Function

Public Function fExecute(pCommand$)
Dim InitString As String
InitString$ = fGetInitString$()

aVersion = fEnsureWorkbench()

If aVersion = 0 Then
Exit Function
ElseIf aVersion <= 3 Then
Dim h_Atom As Long
Dim h_Window As Long

h_Window = FindWindowA("TW4Win2Class", vbNullString)

h_Atom = GlobalAddAtomA(InitString$ + "#" + pCommand$)
fExecute = SendMessageA(h_Window, WM_USER + 2, h_Atom, 0)
GlobalDeleteAtom (h_Atom)
Else
fExecute = oWorkbench.ExecuteWordCommandLong(InitString$ + "#" + pCommand$)
End If
End Function

Private Function fGetInitString$()
aVersion$ = Application.VERSION
aVersion$ = Left$(aVersion$, InStr(aVersion$, ".") - 1)
aLanguage$ = WordBasic.[AppInfo$](16)

fGetInitString$ = Str$(VERSION) + "#Word" + aVersion$ + "#" + aLanguage$
End Function

Private Function fEnsureWorkbench()
On Error Resume Next

' check whether WB is still alive
If Not oWorkbench Is Nothing Then
'get version string to test whether TWB responds
aVersion$ = oWorkbench.VERSION

If Err.Number <> 0 Then
Set oWorkbench = Nothing
End If
End If

' try to launch WB if it does not exist
If oWorkbench Is Nothing Then
Set oWorkbench = GetObject(, "TW4Win.Application")
End If

If oWorkbench Is Nothing Then
MsgBox "Trados Translator's Workbench is not running.", _
vbExclamation + vbOKOnly, "TRADOS Translator's Workbench"
fEnsureWorkbench = 0
Else
aVersion$ = oWorkbench.VERSION
fEnsureWorkbench = Val(Left$(aVersion$, InStr(aVersion$, ".") - 1))
End If
End Function

Public Sub sPushFindSettings()
With Selection.Find
FindText$ = .Text
b_MatchWholeWord = .MatchWholeWord
b_Forward = .Forward
b_MatchCase = .MatchCase
b_MatchWildCards = .MatchWildcards
b_MatchSoundsLike = .MatchSoundsLike
b_MatchAllWordForms = .MatchAllWordForms
End With
End Sub

Public Sub sPopFindSettings()
With Selection.Find
.Text = FindText$
.MatchWholeWord = b_MatchWholeWord
.Forward = b_Forward
.MatchCase = b_MatchCase
.MatchWildcards = b_MatchWildCards
.MatchSoundsLike = b_MatchSoundsLike
.MatchAllWordForms = b_MatchAllWordForms
End With
End Sub

Public Sub sGotoIndexBegin()
Selection.End = ActiveDocument.Bookmarks("tw4winUpto").Range.End
Selection.Find.Execute FindText:=Chr(34)
Selection.Start = Selection.Start + 1
Selection.Collapse
End Sub


Public Sub sAddTagStyles()
Dim aStyles
Dim aExternalFound
Dim aInternalFound
Dim aStyle$
WordBasic.StartOfDocument
WordBasic.CharRight 1, 1
Selection.CopyFormat
WordBasic.ResetChar
WordBasic.FormatStyle Name:="tw4winNone", Type:=1, _
AddToTemplate:=0, Define:=1

aStyles = WordBasic.CountStyles()

aExternalFound = 0
aInternalFound = 0
While aStyles
aStyle$ = WordBasic.[StyleName$](aStyles)
If aStyle$ = "tw4winExternal" Then
aExternalFound = -1
ElseIf aStyle$ = "tw4winInternal" Then
aInternalFound = -1
End If
If aExternalFound < 0 And aInternalFound < 0 Then
aStyles = 0
Else
aStyles = aStyles - 1
End If
Wend

If aExternalFound = 0 Then
WordBasic.FormatStyle Name:="tw4winExternal", _
Type:=1, AddToTemplate:=0, Define:=1
WordBasic.FormatDefineStyleFont Font:="Courier New", Color:=15
End If

If aInternalFound = 0 Then
WordBasic.FormatStyle Name:="tw4winInternal", _
Type:=1, AddToTemplate:=0, Define:=1
WordBasic.FormatDefineStyleFont Font:="Courier New", Color:=6
End If

Selection.PasteFormat
WordBasic.CharLeft 1, 0
End Sub

Public Function fSaveClipboardContents(sClip)
Rem code kindly provided by coolejo to save clipboard contents
Dim ClipboardData As DataObject
On Error Resume Next
Set ClipboardData = New DataObject
ClipboardData.GetFromClipboard
sClip = ClipboardData.GetText
Rem End code by coolejo to save clipboard contents
End Function

Public Function fRestoreClipboardContents(sClip)
Rem code kindly provided by coolejo to save clipboard contents
Set ClipboardData = New DataObject
ClipboardData.SetText sClip
ClipboardData.PutInClipboard
Rem End code kindly provided by coolejo to save clipboard contents
End Function


Public Function fFind(pFind$, pDirection, pPattern, pWrap, pFormat)
fFind = 0
On Error GoTo -1: On Error GoTo eFind

If pFormat = 0 Then
WordBasic.EditFindClearFormatting
WordBasic.EditReplaceClearFormatting
End If

WordBasic.EditFind Find:=pFind$, Replace:="", _
Direction:=pDirection, Wrap:=pWrap, Format:=pFormat, _
PatternMatch:=pPattern, SoundsLike:=0, _
MatchCase:=0, WholeWord:=0

fFind = WordBasic.EditFindFound()
eFind:
On Error GoTo -1: On Error GoTo 0
End Function


Public Function fReplace(pOne, pFind$, pReplace$, _
pDirection, pPattern, pWrap)
fReplace = 0
On Error GoTo -1: On Error GoTo eReplace

WordBasic.EditFindClearFormatting
WordBasic.EditReplaceClearFormatting

If pOne Then
WordBasic.EditReplace Find:=pFind$, Replace:=pReplace$, _
Direction:=pDirection, Wrap:=pWrap, Format:=0, _
PatternMatch:=pPattern, SoundsLike:=0, _
MatchCase:=0, WholeWord:=0, _
ReplaceOne:=1
Else
WordBasic.EditReplace Find:=pFind$, Replace:=pReplace$, _
Direction:=pDirection, Wrap:=pWrap, Format:=0, _
PatternMatch:=pPattern, SoundsLike:=0, _
MatchCase:=0, WholeWord:=0, _
ReplaceAll:=1
End If

fReplace = WordBasic.EditFindFound()
eReplace:
On Error GoTo -1: On Error GoTo 0
End Function


Public Function fSetCloseOpenGet(Optional bToFuzzy As Boolean = False)
b_ShowHidden = ActiveWindow.View.ShowHiddenText
ActiveWindow.View.ShowHiddenText = True
b_ReplaceSelection = Options.ReplaceSelection
Options.ReplaceSelection = True

If b_HasFootnotes Then
n_FootnoteSegment = nGetNextFootnote(s_FNProcessed)
If n_FootnoteSegment > 0 Then
i_Result = fSubSegment(n_FootnoteSegment)
GoTo eSetCloseOpenGet
Else
s_FNProcessed = ""
End If
End If

Dim n_Flag As Integer
n_Flag = 1

If bToFuzzy Then
i_Result = fRequest("", "SetCloseOpenGet#1#")
n_Flag = n_Flag + 1
Else
i_Result = fRequest("", "SetCloseOpenGet#0#")
End If
If i_Result >= 0 Then
GoTo eSetCloseOpenGet
End If

If Abs(i_Result) Mod 10 = 8 Then
'standalone footnote
ActiveDocument.Bookmarks("tw4winFrom").Delete
ActiveDocument.Bookmarks("tw4winUpto").Delete

i_Result = i_Open(n_Flag)

ElseIf Abs(i_Result) Mod 10 = 9 Then
'no more sentences in current paragraph
i_Result = 1
While i_Result >= 1
If WordBasic.ParaDown(1, 0) = 0 Or fNextTextParagraph() = 0 Then
If n_InNote = 0 Then
i_Result = fExecute("Clear#1#")
GoTo eSetCloseOpenGet
ElseIf n_InNote < 10 Then
'subsegment footnote
i_Result = tw4winMain.fMainSegment()
If i_Result >= 0 Then
GoTo eSetCloseOpenGet
End If

n_FootnoteSegment = nGetNextFootnote(s_FNProcessed)
If n_FootnoteSegment > 0 Then
i_Result = fSubSegment(n_FootnoteSegment)
End If

GoTo eSetCloseOpenGet
ElseIf n_InNote < 100 Then
'standalone footnote
i_Result = fMainSegment()
i_Result = fNextTextParagraph()
Else
'Open in footnote pane without mainsegment
i_Result = fMainSegment()
GoTo eSetCloseOpenGet
End If
End If

i_Result = i_Open(n_Flag)
Wend
End If

eSetCloseOpenGet:
fSetCloseOpenGet = i_Result
ActiveWindow.View.ShowHiddenText = b_ShowHidden
Options.ReplaceSelection = b_ReplaceSelection
End Function

Public Function i_Open(n_Flag As Integer)
If bCheckStatus(True) = False Then
Selection.Collapse
Exit Function
End If

n_SelInfo = Selection.Information(wdReferenceOfType)

If Selection.StoryType = wdFootnotesStory Or Selection.StoryType = wdEndnotesStory Then
If Selection.StoryType = wdFootnotesStory Then
n_InNote = 101
Else
n_InNote = 102
End If

n_Offset = Selection.Start - fGetNote(n_InNote, Selection.Range).Range.Start

fGetNote(n_InNote, Selection.Range).Reference.Select

ActiveWindow.SplitVertical = 0

Set o_Footnote = fGetNote(n_InNote, Selection.Range)

sOpenFootnoteWindow (n_Offset)
ElseIf n_SelInfo = 1 Or n_SelInfo = 2 Then
n_InNote = 10 + n_SelInfo

Set o_Footnote = fGetNote(n_InNote, ActiveDocument.Range(Selection.Start))

sOpenFootnoteWindow (0)
End If

Select Case n_Flag
Case 0
i_Result = fRequest("open", "Open#0#")
Case 1
i_Result = fRequest("open", "Open#1#")
Case 2
i_Result = fRequest("open", "Open#2#")
End Select

If Abs(i_Result) Mod 100 >= 10 Then
sGotoIndexBegin
End If

i_Open = i_Result
End Function


Public Function nGetNextFootnote(s_processed As String)
nGetNextFootnote = 0

n_Current = Selection.Start

Selection.GoTo What:=wdGoToBookmark, Name:="tw4winFrom"
Selection.MoveDown wdParagraph, 3

n_Footnote = Selection.Start

Selection.MoveDown wdParagraph, 2
n_Upto = Selection.Start

Set o_Current = ActiveDocument.Range(n_Footnote, n_Upto)

Do
o_Current.Start = n_Footnote
o_Current.End = n_Upto

n_Footnote = 0
If o_Current.Footnotes.Count > 0 Then
n_Footnote = o_Current.Footnotes(1).Reference.Start
End If
If o_Current.Endnotes.Count > 0 Then
n_Endnote = o_Current.Endnotes(1).Reference.Start

If n_Endnote < n_Footnote Then
n_Footnote = n_Endnote
End If
End If

If n_Footnote > 0 Then
o_Current.Start = n_Footnote - 3
o_Current.End = n_Footnote

If (Left$(o_Current.Text, 1) = "{" Or Left$(o_Current.Text, 1) = "1") And _
(Right$(o_Current.Text, 1) = ">") Then
If Left$(o_Current.Text, 1) = "{" Then
o_Current.Start = n_Footnote - 2
End If

o_Current.End = n_Footnote - 1

n_SubSegment = Val(o_Current.Text)

If InStr(s_processed, "," & o_Current.Text & ",") = 0 Then
nGetNextFootnote = n_SubSegment
Exit Function
End If
End If

n_Footnote = n_Footnote + 1
End If
Loop While n_Footnote > 0

Selection.Start = n_Current
Selection.Collapse
End Function


Public Function fFindTemplate() As Template
Dim templ As Template

For Each templ In Templates
If LCase(templ.Name) = "trados7.dot" Then
Exit For
End If
Next

Set fFindTemplate = templ
End Function

Function fGetNote(n_Footnote, o_Range As Range) As Object
If n_Footnote Mod 10 = 1 Then
Set fGetNote = o_Range.Footnotes(1)
Else
Set fGetNote = o_Range.Endnotes(1)
End If
o_Range.Select
End Function
 
N

Nomey

Or is the shading and border formatting determined in this function? Where does one find the vba constants needed to change formatting?

Best regards,
Nomey

==========code============

Private Function fCleanBordersShading()
Dim aShading
Dim aForeground
Dim aBackground
Dim aLine
Dim aColor
Dim aFound
On Error GoTo -1: On Error GoTo eCleanBordersShading
fCleanBordersShading = 0

Dim rFBS As Object: Set rFBS = WordBasic.DialogRecord.FormatBordersAndShading(False)
WordBasic.CurValues.FormatBordersAndShading rFBS

aShading = rFBS.Shading
aForeground = rFBS.Foreground
aBackground = rFBS.Background

aLine = rFBS.LeftBorder
aColor = rFBS.LeftColor

If aShading = 5 And aBackground = 8 And _
(aForeground = 3 Or aForeground = 4 _
Or aForeground = 7 Or aForeground = 16) _
And rFBS.LeftBorder = 1 And rFBS.LeftColor = 16 _
And rFBS.TopBorder = 1 And rFBS.TopColor = 16 _
And rFBS.RightBorder = 1 And rFBS.RightColor = 16 _
And rFBS.BottomBorder = 1 And rFBS.BottomColor = 16 Then
Rem EditReplace .Find = "^0013", \
Rem .Replace = "", .Direction = 0, \
Rem .MatchCase = 0, .WholeWord = 0, .PatternMatch = 1, \
Rem .Format = 0, .Wrap = 0, .ReplaceOne

aFound = WordBasic.Call("tw4winMain.fReplace", 1, "^0013", "", 0, 1, 0)

fCleanBordersShading = -1
End If

eCleanBordersShading:
On Error GoTo -1: On Error GoTo 0
End Function
 
N

Nomey

Hi rVo,

I'm sorry to bother you with such a huge stack of code: the formatting was probably in a short function that is used by the main code in my first message. See my self-reply for the function code. Would you care to check that out? It seems to be a WordBasic command (I forgot most of that).

Thanks in advance,
Nomey
 
R

rVo

Obviously this is getting you where you need to be, but I don't know much
about Word basic either... Sorry

Nomey said:
Or is the shading and border formatting determined in this function? Where
does one find the vba constants needed to change formatting?
 
N

Nomey

Well, thanks for trying anyway. And you don't know where to find those color values (constants) either?
 
H

Helmut Weber

Hi Nomey,

seach for wdColor in the object browser.

Try to modify these lines:

aShading = rFBS.Shading
aForeground = rFBS.Foreground
aBackground = rFBS.Background

like:

aShading = wdcolorred
aForeground = wdcolorlime
aBackground = wdcolorgray50
 
N

Nomey

Hi Helmut,

Thanks for your suggestion, but it doesn't work. The function seems to clean up these formatting options rather than setting them. I suppose you don't have any idea where the formatting is set in this macro? (see the main module in my first posting of today)

Best regards,
Nomey
 
L

Lesley Regan

--




Nomey said:
Hi Helmut,

Thanks for your suggestion, but it doesn't work. The function seems to clean up these formatting options rather than setting them. I suppose you don't have any idea where the formatting is set in this macro? (see the main module in my first posting of today)

Best regards,
Nomey

Nomey,

n_FootnoteHighlight = o_Footnote.Reference.HighlightColorIndex
o_Footnote.Reference.HighlightColorIndex = wdYellow


Have you examined this pair of lines in your code?

Good luck,

Lesley
 
N

Nomey

Hi Lesley,

Yes, now I have checked "wdYellow", but it's not the code that creates shading. Thanks for trying and best regards,

Nomey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top