21

述べたように、VBA (Visual Basic for Applications) で指定されたインデックスで文字列から文字を取得する方法は? 私はGoogleを検索しましたが、これらは機能しません:

s(index)s.Chars(index)s,Characters(index)

では、指定されたインデックスで char を取得する方法は?

4

3 に答える 3

38

このs方法で行うことができるよりも文字列である場合:

Mid(s, index, 1)

質問の下のコメントに基づいて編集します。

少し異なるアプローチが必要なようです。この方法で試してください:

Dim character As String 'Integer if for numbers
's = ActiveDocument.Content.Text - we don't need it
character = Activedocument.Characters(index)
于 2013-06-15T19:49:46.227 に答える
1

指定されたインデックスの文字列から 1 文字を取得する

Dim pos As Integer
Dim outStr As String
pos = 2 
Dim outStr As String
outStr = Left(Mid("abcdef", pos), 1)

outStr="b"

于 2015-12-18T16:11:19.850 に答える