Share via

VBA Word,information() runtime error 4608 value out of range

Anonymous
2018-03-23T02:45:39+00:00

The code is to get all comments from a docx file, get the page and line of each comment


Sub exportWordComments\_Click()

'Dim Cmt As Comment

Dim excelApp As Object

Dim xlsWbk, objWdApp As Object

Dim commentsArray

Dim rows, temp, i As Integer

Dim filename As String

'Dim myWDoc As Word.Document

'get file name

filename = Application.GetOpenFilename

If filename = "False" Then

Exit Sub

End If

Set objWdApp = CreateObject("word.application")

objWdApp.Visible = True '启动word应用程序

Set mywdoc = objWdApp.Documents.Open(filename)

rows = mywdoc.Comments.Count

ReDim commentsArray(1 To rows, 1 To 5)

For i = 1 To rows

temp = temp + 1

'page

\*\*commentsArray(temp, 1) = mywdoc.Comments(i).scope.Information(wdActiveEndPageNumber)\*\*

'line

\*\*commentsArray(temp, 2) = mywdoc.Comments(i).scope.Information(wdFirstCharacterLineNumber)\*\*

'批注引用内容

commentsArray(temp, 3) = mywdoc.Comments(i).Scope

'批注内容

commentsArray(temp, 4) = mywdoc.Comments(i).Range.Text

'作者

commentsArray(temp, 5) = mywdoc.Comments(i).Author

Next

Set excelApp = CreateObject("Excel.Application")

'打开批注表

Set xlsWbk = excelApp.Workbooks.Add

With xlsWbk.Sheets(1)

.Cells.Clear

.Range("A2").Resize(rows, 5) = commentsArray

.Range("A1") = "页码"

.Range("B1") = "行号"

.Range("C1") = "批注选中的原文字"

.Range("D1") = "批注内容"

.Range("E1") = "批注作者"

.Columns.AutoFit

End With

xlsWbk.SaveAs mywdoc.Path & Application.PathSeparator & "修订表.xlsx"

xlsWbk.Close

excelApp.Application.Quit

End Sub

I changed word file or information style , can not solve this problem

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2018-03-24T12:10:12+00:00

    Since you are performing this as an Excel macro, it's probably best if you ask for help from those experts, so I am moving this to that Office Programming category.

    Most likely the error message is coming from your ReDim statement. Only one dimensional arrays work with a ReDim statement.

    Was this answer helpful?

    0 comments No comments