System.Runtime.InteropServices.COMException: 'El comando falló'

Mihai Manea 96 Reputation points
2021-12-03T12:48:55.293+00:00

Hi,

I am trying to get coordinates of a bookmark item on a word document.

Dim w = wApp()
Dim doc = w.Documents.Open(DOCFileName, , True)
Dim v As Word.Window = doc.ActiveWindow
Dim izq As Int32, sup As Int32, ancho As Int32, largo As Int32
Dim r As Word.Range

doc.Application.Visible = True

r = doc.Bookmarks.Item("ANYOFIRMA").Range

Until here the variables apparently have values and no error popped up.

v.GetPoint(izq, sup, ancho, largo, r) -> This output the error: System.Runtime.InteropServices.COMException: 'El comando falló'

I am lost and I don't know what else to try.

Cheers

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,835 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,579 questions
Word Management
Word Management
Word: A family of Microsoft word processing software products for creating web, email, and print documents.Management: The act or process of organizing, handling, directing or controlling something.
893 questions
{count} votes

Accepted answer
  1. Mihai Manea 96 Reputation points
    2021-12-09T07:37:12.193+00:00

    Hello,

    I have updated the question with the v declaration.

    Sorry I have forgotten to add it.

    Edit:

    I had to change the hard disk to a copy of my co-worker and it works. No idea why. :(

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. RLWA32 40,651 Reputation points
    2021-12-09T09:48:21.147+00:00

    I could not reproduce the problem with my copy of Word.

    Code snippet -

                Dim wApp As Application  
                Dim d As Document  
                Dim b As Bookmark  
                Dim r As Range  
                Dim v As Window  
                Dim izq As Int32, sup As Int32, ancho As Int32, largo As Int32  
      
                wApp = New Application()  
                wApp.Visible = True  
                d = wApp.Documents.Open("C:\Users\RLWA32\Documents\BOOKTEST.docx")  
                b = d.Bookmarks("BOOKTEST")  
                v = d.ActiveWindow  
                r = b.Range  
                v.GetPoint(izq, sup, ancho, largo, r)  
      
    

    Variables in debugger -

    156167-word.png