"Magnus Andersson" <ma****************@bredband.net> wrote in message
news:7e************************@posting.google.com ...
I really need some help with a Visual Basic problem. I am using Visual
Basic .NET and want find some text with a certain style in an MS
Office document. I have written something like:
Dim oFind As Object
oDoc.Content.Select()
oFind = oWord.Selection.Find
oFind.ClearFormatting()
oFind.Style = oDoc.Styles("MyStyle").Style ' <= The error occurs here.
oFind.Execute(FindText:="", Forward:=True, Format:=True)
I get the following build error: "'Font' is not a by reference
property". OK, so the right side of the erronous expression returns a
reference and the left side expects a value, but how the heck do I
convert to a value?? I can't find any information about this in the
Visual Studio help files or on the web.
Does anybody have any suggestions?
While Rick is right to point you to VB.Net groups, the fact is your problem is
one in MS Office, which is VBA, which is (sometimes) covered in this group as
well.
I believe that all you need to do to find the style you are looking for is
oFind.Style = "MyStyle"
My documentation is for Office 97, but it says "To set this property, specify
either the local name of the style, an integer or a WdBuiltinStyle constant (see
"Remarks"), or an object that represents the style."
You could set the style object ( I think), with the line
Set oFind.Style = oDoc.Styles("MyStyle")
but I don't think it is necessary.
You should be able to set a reference to MS Office objects, or MSWord objects,
and be able to write
Dim oFind as Word.Find
instead of the generic object class. That would get you more pop-up help, as
well as better performance.