By reference property?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Magnus Andersson

    By reference property?

    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.Se lect()
    oFind = oWord.Selection .Find
    oFind.ClearForm atting()
    oFind.Style = oDoc.Styles("My Style").Style ' <= The error occurs here.
    oFind.Execute(F indText:="", 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?
  • Rick Rothstein

    #2
    Re: By reference property?

    Almost everybody in this newsgroup is using VB6 or lower. While you may get
    a stray answer to VB.NET questions here, you should ask them in newsgroups
    devoted exclusively to .NET programming. Look for newsgroups with either the
    word "dotnet" or "vsnet" in their name.

    For the microsoft news server, try these newsgroups...

    microsoft.publi c.dotnet.genera l
    microsoft.publi c.dotnet.langua ges.vb
    microsoft.publi c.vsnet.general

    For the news.devx.com news server, try these

    vb.dotnet.discu ssion
    vb.dotnet.techn ical

    There are some others, but these should get you started.

    Rick - MVP




    "Magnus Andersson" <magnus76.ander sson@bredband.n et> wrote in message
    news:7e8e726.03 11040905.c16001 5@posting.googl e.com...[color=blue]
    > 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.Se lect()
    > oFind = oWord.Selection .Find
    > oFind.ClearForm atting()
    > oFind.Style = oDoc.Styles("My Style").Style ' <= The error occurs here.
    > oFind.Execute(F indText:="", 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?[/color]


    Comment

    • Steve Gerrard

      #3
      Re: By reference property?


      "Magnus Andersson" <magnus76.ander sson@bredband.n et> wrote in message
      news:7e8e726.03 11040905.c16001 5@posting.googl e.com...[color=blue]
      > 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.Se lect()
      > oFind = oWord.Selection .Find
      > oFind.ClearForm atting()
      > oFind.Style = oDoc.Styles("My Style").Style ' <= The error occurs here.
      > oFind.Execute(F indText:="", 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?[/color]

      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("My Style")

      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.


      Comment

      • Magnus Andersson

        #4
        Re: By reference property?

        >[color=blue]
        > 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("My Style")
        >
        > 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.[/color]


        Thanks for the answer! I will try that instead. I am rewriting a
        script I wrote in Python, and then "oFind.Styl e =
        oDoc.Styles("My Style")" worked.


        I was writing the previous post a little too fast I realized, and
        there were some errors. For instance it should be "Set oFind.Style =
        oDoc.Styles("My Style")" and not "Set oFind.Style =
        oDoc.Styles("My Style").Style", and the compiler complains about
        "Style" not being a by reference property and not "Font". (I tried to
        write "Set oFind.Font = oDoc.Styles("My Style").Font" as well and got a
        similar error and then copied and pasted too fast.)

        Comment

        Working...