我有sValA = 10/140/000
字符串。
需要在从右到左文档中插入 10/140/000 作为文字。
当我在下面执行时
ThisDocument.Bookmarks("Temp_GrandTotal").Range.Text = sValA
返回 000/140/10
感谢任何帮助。
答案 0 :(得分:1)
您需要在Selection
对象上调用Range
方法,您可以从ThisDocument.Bookmarks("Temp_GrandTotal").Range.Select
Selection.LtrRun
对象获取该方法:
%in%
这告诉Word,这个方向中性字符序列的方向应该是从左到右,与文档的其他部分不同。
答案 1 :(得分:1)
尝试:
Sub UpdateRTLBookmark(StrBkMk As String, StrTxt As String)
Dim RngBkMk As Range, RngSel As Range
With ActiveDocument
If .Bookmarks.Exists(StrBkMk) Then
Set RngSel = .Selection.Range
Set RngBkMk = .Bookmarks(StrBkMk).Range
RngBkMk.Text = StrTxt
RngBkMk.Select
Selection.RtlRun
.Bookmarks.Add StrBkMk, RngBkMk
RngSel.Select
End If
End With
Set RngBkMk = Nothing: Set RngSel = Nothing
End Sub
您可以使用以下代码调用:
Sub Demo()
Application.ScreenUpdating = False
Dim StrBkMk As String, StrTxt As String
StrBkMk = "Temp_GrandTotal": StrTxt = "10/140/000"
Call UpdateRTLBookmark(StrBkMk, StrTxt)
Application.ScreenUpdating = True
End Sub
这种方法的优点是,如果需要,您可以再次更新已添加书签的范围。
如果希望文本为LTR格式,请将Selection.RtlRun更改为Selection.LtrRun。我也改变了宏名。
答案 2 :(得分:0)
您可以添加UDF以通过交换字符交换部件。然后称它为:
ThisDocument.Bookmarks("Temp_GrandTotal").Range.Text = SwapParts(sValA,"\")
UDF代码:
Option Explicit
Function SwapParts(ByVal sText As String, ByVal SwapChar As String) As String
Dim oItems As Variant, oItem As Variant, sOutput As String
oItems = Split(sText, SwapChar)
For Each oItem In oItems
If Len(sOutput) > 0 Then sOutput = SwapChar & sOutput
sOutput = oItem & sOutput
Next oItem
SwapParts = sOutput
End Function