Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selection.TypeText not the same in C# (Word 2000/sr1)

    We are using the Word object via C# buit are having trouble using Selection.TypeText when trying to send a "Tab" key command. In VB the command would be Slection.TypeText(Text:=vbTab) and in C# this is not allowed. We have tried Selection.TypeText(Word.WdKey.vbTab) and
    Selection.TypeText(Word.WdKey.vbTab.ToString) with no success. Any ideas?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Selection.TypeText not the same in C# (Word 2000/sr1)

    The vbWhatever constants are defined in a file that is not included in your C# project because... it's not in VB. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    VBE's Immediate window says:

    <pre>?asc(vbtab)
    9 </pre>

    Can you use that information to generate the right character in C# or to define vbTab as a constant?

    BTW, you shouldn't need to use () around the method's arguments unless it is on the right side of an assignment statement.

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Selection.TypeText not the same in C# (Word 2000/sr1)

    Haven't touched .NET in a couple of months, so may be misrecalling, but I think all arguments must have the ()'s, unlike in VB/VBA.

    Gary

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selection.TypeText not the same in C# (Word 2000/sr1)

    You have to issue the VBA via a reference to the Word object in the C# program.
    You cannot enter the VBA itself without such an object qualifier.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •