Word VBA使用特殊字符插入字符串

时间:2014-01-27 12:04:04

标签: ms-word word-vba

代码段

String1 = "the quick brown" & " fox " &  "jumped over..."
With wdoc.Tables(pos)
   .Rows(1).Cells(1).Range.Text = String1
End with

OK足够简单 - 分配字符串然后将字符串分配给单元格。

我想做的是告诉“狐狸”这个词他是大胆的。可以这样做吗?是否有特殊的字符序列?例如^ B,有谁知道可以找到完整列表的位置?文本显然可以是任何东西......

感谢和问候 肖恩

1 个答案:

答案 0 :(得分:1)

我只能针对您的需求提出解决方法 - 据我所知,没有任何简单的解决方案可以解决这个问题。请参阅代码中的一些注释和解释。

'put each part of your text into array,
'No white-spaces inside quotation marks
String1 = Array("the quick brown", "fox", "jumped over...")

'let's change With structure a bit:
With wDoc.Tables(pos).Rows(1).Cells(1)

    'put text to table as a result of Joining all array elements
   .Range.Text = Join(String1, " ")

   'assuming you want to bold 2nd element of your text/array which ever long it is
   'we search range within document which refers to this part of our text
   'which could be done in this way:
   wDoc.Range( _
                .Range.Start + Len(String1(0)), _
                .Range.Start + Len(String1(0)) + Len(String1(1)) + 1). _
                Font.Bold = True

End With

,结果如下所示:

enter image description here