VBA Error 462

FlavorFlav

New Member
Joined
Mar 29, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi all!

I am struggling with the VBA error 462. I checked multiple other pages with a similar issue, but no of them did help me really. It is just changing the place in the code where the error occurs.

Shortly what I did:

- For Requirements Engineering & Changge request managment I need an Excel which helps me to write down meeting notes with our clients. The idea is to start everything from Excel (Mails, Tasks, Word, etc.), which works perfectly fine except the Error 462.

The line of code is the following, where the "WordFullName" is a combination of the File Path to Sharepoint & the file name (e.g. https://asdadasda.sharepoint.com/:w:/s/PR..../ProjectAAA.docx". This is checked with an "URL existance function" (which works fine after a lot of research). But in the following part of code I get sometimes an error message 462.

Can anybody help me there? I tried several other option to solve this error, but it only moves the line of code which the error is showing. After "reseting" the VBA Code, the Sub procedure is running without problems again for 1 round.

Thanks in Advance!
---------------------------------------------------


Rich (BB code):
Sub TableWord(WordFullName As String) 

Dim myRange, myTable As Object
Dim OApp As Word.Application


Set OApp = New Word.Application
OApp.Documents.Open (WordFullName)
OApp.Visible = True

Set myRange = OApp.ActiveDocument.Range(Start:=0, End:=0)

 If OApp.ActiveDocument.Tables.Count = 0 Then ' Check if table already exists
 
            OApp.ActiveDocument.Tables.Add Range:=myRange, NumRows:=2, NumColumns:=2
            Set myTable = OApp.ActiveDocument.Tables(1)
            myTable.AutoFormat , 1, 1, 1, 1, 0, 0, 0, 0, 1
           
            With myTable.Borders ' For new table
                .InsideLineStyle = wdLineStyleSingle
                .OutsideLineStyle = wdLineStyleDouble
            End With
       
            With myTable.Cell(1, 1).Range
                .Delete
                .InsertAfter Text:="Date"
            End With
       
            With myTable.Cell(1, 2).Range
                .Delete
                .InsertAfter Text:="Topic"
            End With
           
            With myTable.Cell(2, 1).Range
                .Delete
                .InsertAfter Text:=ActiveSheet.Range("A46").Value
            End With
           
            With myTable.Cell(2, 2).Range
                .Delete
                .InsertAfter Text:=Sheets("Names_Code").Range("C36").Value
            End With
           
            myTable.Columns(1).Width = InchesToPoints(1.1)
            myTable.Columns(2).Width = InchesToPoints(5.2)
           
        Else
       
        Set myTable = OApp.ActiveDocument.Tables(1) ' For existing table
        myTable.Rows.Add BeforeRow:=myTable.Rows(2)
            
            With myTable.Cell(2, 1).Range
                .Delete
                .InsertAfter Text:=ActiveSheet.Range("A46").Value
            End With
           
            With myTable.Cell(2, 2).Range
                .Delete
                .InsertAfter Text:=Sheets("Names_Code").Range("C36").Value
            End With
            
            myTable.Columns(1).Width = InchesToPoints(1.1)
            myTable.Columns(2).Width = InchesToPoints(5.2)
       
        End If

End Sub
 
Last edited by a moderator:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
The only possible issue I can see there is that both Word and Excel have an InchesToPoints method, so perhaps you should use Application.InchesToPoints rather than just InchesToPoints
 
Upvote 0
Solution
Thanks a lot for your help! It works now perfect! You saved me a lot of time to test all other possible solutions :)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top