0

Okay, I am a Javascript programmer and VBA is driving me insane - I know nothing about it and it is like pulling teeth to find simple documentation on the simplest thing.

I'm literally trying to run a little script to auto-format a document, partly based in content.

I want to grab the third line of document, or first 100 characters, I really don't care, and run the equivalent of String().indexOf('foobar') on it, to check if that part of the document contains a string.

I cannot for the life of me find how to:

a. Load text selection into a variable.
b. Run a sane semblance to indexOf.

Can someone please help? And maybe point me to a sane VBA documentation that is not Micrsoft?

4

1 に答える 1

0

a. Load text selection into a variable.

Identify a range (Word.Range) you want and get the Text property of that range.
For instance,

dim s as string
s = ThisDocument.Paragraphs(3).Range.Text

b. Run a sane semblance to indexOf.

Is InStr no good?

msgbox InStr(s, "foobar")
于 2013-02-23T01:45:29.840 に答える