Share via

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

Developer technologies | Windows Forms
Microsoft 365 and Office | Word | For business | Windows
Developer technologies | VB

Answer accepted by question author

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. :(

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. RLWA32 52,566 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

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.