Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Runtime error 1004 application-defined or object-defined error

I tried to pose this on another group, MS Excel and VBA, but it
still has not been posted, and I realize now that this group is much
more active and accessible. . . .

I am getting the error: "Runtime error 1004 application-defined or
object-defined error" in the code provided below at this line of
code:

.Cells(StartRow + n - 1, 5).Value = _
WordDoc.Comments(n).Scope


It is processing comments in a Word document and outputting them into
Excel cells. It works fine on another document, but not on this
particular document. However, the debug statements I inserted prior
to this (see code below) output fine.


Anyone have any idea what might cause this?


Thanks, Alan


Public Sub Extract(WordApp As Object, WordDoc As Object)


Const StartRow = 2
Dim CommentWorkbook As Workbook, CommentSheet As Worksheet
Dim nCount As Long
Dim n As Long


' Set up access to the Excel worksheet
Set CommentWorkbook = ActiveWorkbook
Set CommentSheet = CommentWorkbook.Worksheets("Comments")


' Make sure the right worksheet can be accessed
If CommentSheet Is Nothing Then
Error.ShowErrorMsg "Unable to find the worksheet named
'Comments'", "Excel Worksheet Error"
GoTo SafeExit
End If


' Determine how many comments are in the Word document
nCount = WordDoc.Comments.Count


' If no comments are found, exit
If nCount = 0 Then
Error.ShowErrorMsg "The active document contains no
comments!", "No Comments Found", "ExtractWordComments.Extract"
GoTo SafeExit
End If


' Application.ScreenUpdating = False


'Get info from each comment in WordDoc, and insert in spreadsheet
For n = 1 To nCount
With CommentSheet
' Comment number
.Cells(StartRow + n - 1, 1).Value = n
' Author name
.Cells(StartRow + n - 1, 2).Value = _
WordDoc.Comments(n).Author
' Page number
.Cells(StartRow + n - 1, 3).Value = _


WordDoc.Comments(n).Scope.Information(Word.wdActiv eEndPageNumber)
'The text marked by the comment\
Debug.Print "Comment # " & n & " - Cell(" & StartRow
+
n - 1 & ", 5)"
Debug.Print "Cell value: " & .Cells(StartRow + n - 1,
5).Value
Debug.Print "Comment scope: " & WordDoc.Comments(n).Scope
Debug.Print "--- reached end of scope"
.Cells(StartRow + n - 1, 5).Value = _
WordDoc.Comments(n).Scope
'The comment itself
Debug.Print "Getting the comment itself . . ."
.Cells(StartRow + n - 1, 6).Value = _
WordDoc.Comments(n).Range.Text
End With
Next n


' Application.ScreenUpdating = True
' Application.ScreenRefresh


CommentSheet.Activate
MsgBox nCount & " comments found. Finished creating comments
document.", vbOKOnly, "Success!"


SafeExit:
Set CommentWorkbook = Nothing
Set CommentSheet = Nothing
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Runtime error 1004 application-defined or object-defined error

Alan,
this may be a long shot. The debug.Print statement that works
transforms the Scope value into a string:
Debug.Print "Comment scope: " & WordDoc.Comments(n).Scope

Your code that chokes tries to assign it to the value property of the cell.
I would try something like:
.Cells(StartRow + n - 1, 5).Value = _
CStr(WordDoc.Comments(n).Scope)
or
.Cells(StartRow + n - 1, 5).Value = _
"" & WordDoc.Comments(n).Scope

I'm not familiar with the Word Objects so I don't know what data/data type
Scope can contain, but if this is the problem one of the above should solve it.

Helmut.


"Alan" schrieb im Newsbeitrag
...
I tried to pose this on another group, MS Excel and VBA, but it
still has not been posted, and I realize now that this group is much
more active and accessible. . . .

I am getting the error: "Runtime error 1004 application-defined or
object-defined error" in the code provided below at this line of
code:

.Cells(StartRow + n - 1, 5).Value = _
WordDoc.Comments(n).Scope


It is processing comments in a Word document and outputting them into
Excel cells. It works fine on another document, but not on this
particular document. However, the debug statements I inserted prior
to this (see code below) output fine.


Anyone have any idea what might cause this?


Thanks, Alan


Public Sub Extract(WordApp As Object, WordDoc As Object)


Const StartRow = 2
Dim CommentWorkbook As Workbook, CommentSheet As Worksheet
Dim nCount As Long
Dim n As Long


' Set up access to the Excel worksheet
Set CommentWorkbook = ActiveWorkbook
Set CommentSheet = CommentWorkbook.Worksheets("Comments")


' Make sure the right worksheet can be accessed
If CommentSheet Is Nothing Then
Error.ShowErrorMsg "Unable to find the worksheet named
'Comments'", "Excel Worksheet Error"
GoTo SafeExit
End If


' Determine how many comments are in the Word document
nCount = WordDoc.Comments.Count


' If no comments are found, exit
If nCount = 0 Then
Error.ShowErrorMsg "The active document contains no
comments!", "No Comments Found", "ExtractWordComments.Extract"
GoTo SafeExit
End If


' Application.ScreenUpdating = False


'Get info from each comment in WordDoc, and insert in spreadsheet
For n = 1 To nCount
With CommentSheet
' Comment number
.Cells(StartRow + n - 1, 1).Value = n
' Author name
.Cells(StartRow + n - 1, 2).Value = _
WordDoc.Comments(n).Author
' Page number
.Cells(StartRow + n - 1, 3).Value = _


WordDoc.Comments(n).Scope.Information(Word.wdActiv eEndPageNumber)
'The text marked by the comment\
Debug.Print "Comment # " & n & " - Cell(" & StartRow
+
n - 1 & ", 5)"
Debug.Print "Cell value: " & .Cells(StartRow + n - 1,
5).Value
Debug.Print "Comment scope: " & WordDoc.Comments(n).Scope
Debug.Print "--- reached end of scope"
.Cells(StartRow + n - 1, 5).Value = _
WordDoc.Comments(n).Scope
'The comment itself
Debug.Print "Getting the comment itself . . ."
.Cells(StartRow + n - 1, 6).Value = _
WordDoc.Comments(n).Range.Text
End With
Next n


' Application.ScreenUpdating = True
' Application.ScreenRefresh


CommentSheet.Activate
MsgBox nCount & " comments found. Finished creating comments
document.", vbOKOnly, "Success!"


SafeExit:
Set CommentWorkbook = Nothing
Set CommentSheet = Nothing
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Runtime error 1004 application-defined or object-defined error

Helmut,

Thanks for the suggestion. Unfortunately, that did not fix it.
It`s odd that this happens with one particular document, which does
not appear to have any other problems.

Alan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Runtime error 1004 application-defined or object-defined error


Not knowing much about Word, but having an idea on how to debug; does
this happen with just one of the comments in that document, or all of
them? The aim is to find out whether it's a document oddity or a comment
oddity. If it is just a single comment throwing this error, what's the
comment text?


Alan;727091 Wrote:

Helmut,

Thanks for the suggestion. Unfortunately, that did not fix it.
It`s odd that this happens with one particular document, which does
not appear to have any other problems.

Alan



--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?u=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=203490

http://www.thecodecage.com/forumz

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime Error 1004: Application defined or object defined error Access n00b Excel Programming 2 April 5th 06 02:58 AM
Runtime error 1004- application defined or object defined error Novice Excel Programming 11 February 6th 06 11:02 PM
Runtime error 1004- application defined or object defined erro Novice Excel Programming 0 February 6th 06 09:34 PM
Runtime error 1004- application defined or object defined erro Novice Excel Programming 1 February 6th 06 09:33 PM
Runtime error 1004- application defined or object defined erro Jim Thomlinson[_5_] Excel Programming 0 February 6th 06 09:29 PM


All times are GMT +1. The time now is 07:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"