Vba 在从右向左的MS Word文档中插入格式化的数字作为文本

Vba 在从右向左的MS Word文档中插入格式化的数字作为文本,vba,ms-word,right-to-left,Vba,Ms Word,Right To Left,我有sValA=10/140/000字符串 需要将10/140/000作为文本插入从右向左的文档中 当我在下面表演时 ThisDocument.Bookmarks("Temp_GrandTotal").Range.Text = sValA 它返回000/140/10 非常感谢您的帮助。您需要调用选择对象上的LtrRun方法,您可以从范围对象获得该方法: ThisDocument.Bookmarks("Temp_GrandTotal").Range.Select Selection.LtrRun

我有
sValA=10/140/000
字符串

需要将10/140/000作为文本插入从右向左的文档中

当我在下面表演时

ThisDocument.Bookmarks("Temp_GrandTotal").Range.Text = sValA
它返回000/140/10


非常感谢您的帮助。

您需要调用
选择
对象上的
LtrRun
方法,您可以从
范围
对象获得该方法:

ThisDocument.Bookmarks("Temp_GrandTotal").Range.Select
Selection.LtrRun

这告诉Word,与文档的其余部分不同,此方向中性字符序列的方向应该是从左到右。

您需要调用
选择
对象上的
LtrRun
方法,您可以从
范围
对象获得该方法:

ThisDocument.Bookmarks("Temp_GrandTotal").Range.Select
Selection.LtrRun

这告诉Word,此方向中性字符序列的方向应为从左到右,与文档的其余部分不同。

您可以添加自定义项以通过交换字符交换零件。那么就这样称呼它:

ThisDocument.Bookmarks("Temp_GrandTotal").Range.Text = SwapParts(sValA,"\")
自定义项代码:

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

可以添加自定义项以通过交换字符交换零件。那么就这样称呼它:

ThisDocument.Bookmarks("Temp_GrandTotal").Range.Text = SwapParts(sValA,"\")
自定义项代码:

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
尝试:

您可以使用如下代码调用:

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。我也要更改宏名称。

试试:

您可以使用如下代码调用:

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。我也要更改宏名称。

ThisDocument.Bookmarks(“Temp_GrandTotal”).Range.Text=StrReverse(sValA)
?它返回01/041/000!而我需要10/140/000,如上所述。
ThisDocument.Bookmarks(“Temp_GrandTotal”).Range.Text=StrReverse(sValA)
?它返回01/041/000!而我需要10/140/000,如上所述。错误:
方法或数据成员未找到
,而
LtrRun
已选择。@Tuberrose似乎
LtrRun
仅存在于
选择
上。错误:
方法或数据成员未找到
,当
LtrRun
已选中时。@Tuberrose似乎
LtrRun
只存在于
选项上。非常感谢。实际更改文档文本的一个可能缺点是,如果您需要搜索此格式的内容,您必须将要搜索的文本反转:
000/140/10
,而不是
10/140/000
。非常感谢。实际更改文档文本的一个可能缺点是,如果您需要搜索此格式的内容,您必须反转要搜索的文本:
000/140/10
,而不是
10/140/000
。文档为RTL。为了强制运行从左向右,为什么要调用
.RtlRun
?如果希望文本为LTR格式,请将Selection.RtlRun更改为Selection.LtrRun。我也要更改宏名。文档是RTL。为了强制运行从左向右,为什么要调用
.RtlRun
?如果希望文本为LTR格式,请将Selection.RtlRun更改为Selection.LtrRun。我也会更改宏名称。