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.wdActiveEndPageNumber)
            '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


0
Alan
5/18/2010 1:08:09 PM
excel.programming 6508 articles. 2 followers. Follow

3 Replies
2218 Views

Similar Articles

[PageSpeed] 49

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" <jalanthomas@verizon.net> schrieb im Newsbeitrag 
news:df704756-8a23-4919-862f-9eda71cf8848@s41g2000vba.googlegroups.com...
>   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.wdActiveEndPageNumber)
>            '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
>
>


0
Helmut
5/18/2010 8:54:15 PM
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

0
Alan
5/19/2010 12:02:29 PM
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/showthread.php?t=203490

http://www.thecodecage.com/forumz

0
p45cal
5/19/2010 12:24:15 PM
Reply:

Similar Artilces:

Error message........
After a re-organisation when ever I save my excel file it throws up the message that autopublish cannot find a web address and gives some addresses of a defunct location. I know why it is happening but do not know how to stop the error messages. ...

Visual C++ Run Time error when opening Outlook 2000
I get the following error message when opening Outlook 2000 on a Win98 machine: Runtime Error! Program: C:\Programs\Microsoft Office\Office\Outlook.exe This program has requested the runtime to terminate it in an unusual way. I have uninstalled/reinstalled Office2000. I have downloaded newest updates to Office 2000. I have run a virus check on the PC. I turned off the anti-virus software. I have run the repair utility - all without success. I suspect a problem in the registry, but don't know what to look for. Has anyone come across this problem? Can someone help? I would be eve...

Error installing Extender.
Hi, When I try to install Extender on a machine, I receive the following error: "The required configuration information necessary for installing could not be found on this machine" I have GP 8.0 sp3, Latin American version. Any Idea?? I don´t know what need to check... -- Evelin. Ana - just a guess, but are you logged in as Administrator? Perhaps it's a issue with user rights to access/edit the registry. Brenner @ (www.KlenzmanConsulting.com) "Ana Evelin Rosa" wrote: > Hi, > > When I try to install Extender on a machine, I receive the following...

Function is not availalbe in expressions in query expression error message (0/1)
I recently received this error message when opening the source DB in Access 2007. I have attached two jpg pics. Does this error message give enough details for someone to point me in the right direction for a fix? The last time I developed and worked in this DB everything worked fine. I get this error when clicking on a control that runs a query macro against a backend DB consisting of about 15 tables. I should mention the error comes into play when trying to run the frontend on a client W/S. I don't see the error while on my W/S which is my developer W/S and has Acce...

Convert Lead to Account, Contact, or Opportunity Error CRM 4.0 #2
Hi, in CRM 4.0 when I try to convert a Lead to an account, lead or opportunity it tells me there is an error and to try again. It gives me no details on the error. But when I try to disqualify a lead it allows me to do that. So what would cause me not to be able to convert a lead? Thanks. -- Christina Hi Christina, Do you have any Plug-in associate with Account or Opportunity? If not, I believed a platform trace will able to tell you what is wrong. Darren Liu, Microsoft CRM MVP Crowe Horwath http://www.crowecrm.com On Dec 8, 10:45=A0am, Christina <Christ...@discussions.microsof...

Object Dependencies
We are using Office 2003, but kept our database in the 2000 format. I am unable to use the object dependencies in Access 2003. Could the 2000 format be the problem? Thanks. No, the feature 'works' (in as much as it ever works at all) with 2000 format. It does, however, require that Name AutoCorrect be enabled, and that's something that you really don't want to do. See Allen Browne's article on the subject at the following URL ... http://allenbrowne.com/bug-03.html -- Brendan Reynolds Access MVP "DSmith" <Donna@NOTSPAMres-xraynews.com> wrote in m...

Ole object list
Hi, Is there any way to add a kind of object (ex.: Journal document or OneNote document) in the list of objects of the windows who open after we right clic the command "Insert an object" in a Ole field in Access 2007 (Vista system)? Thanks! ...

Error Code 800736B2
I have a relatively new laptop with Vista, and I cannot install any updates. I receive an error code 800736B2. Lots on the web about removing Kaspersky Internet Security, but I don't seem to have this software. What can I do to update my laptop? 800736B2 ERROR_SXS_INVALID_ACTCTXDATA_FORMAT The application binding data format is invalid. Suggest running the System File Checker: <http://support.microsoft.com/kb/936212> no joy.......then/or Start a free Windows Update support incident request: <https://support.microsoft.com/oas/default.aspx?gprid=6527&...

Object disappears when saving photo
I grouped a text box onto a photo then attempt to save photo as. No matter what file format I chose the photo only saves as the original photo without the text box. The text box disappears every time. I've tried diffrerent fonts, moving the text box forward. I've never had this trouble doing it before. Thanks for any ideas! How about, Save, files of type, scroll down to image formats. If it is too big after you save, you can always bring it into an editing program and crop away the unneeded areas. -- Mary Sauer http://msauer.mvps.org/ "bosox75m" <bosox75m@disc...

how to get the number of milliseconds between two System.DateTime objects
how to get the number of milliseconds between two System.DateTime objects DateTime dt = DateTime.Now; TimeSpan ts = DateTime.Now.Subtract( dt ); Convert.ToString(ts.TotalMilliseconds) ; ...

DSUM error# Syntax problem?
I am trying to use DSUM to create a running total via Method 1 in MS TID 290136. I am getting an error in my DSUM statement. Very simple query: SELECT SalesForGraph.Week AS CWeek, SalesForGraph.[2006Profit], DSum("2006Profit","SalesForGraph","[WEEK] <= " & [Cweek]) AS RunTot FROM SalesForGraph ORDER BY SalesForGraph.Week; The string for Criteria resolves to: [week] <=1 [week] <=2 etc. What am I doing wrong? Phil Changed it to SELECT SalesForGraph.Week AS CWeek, SalesForGraph.[2006Profit], DSum("2006Profit","SalesForGraph&quo...

Error opening Outlook 2007
I am getting a "Either there is no default mail client or the current mail client cannot fulfill the messaging request. Please run Microsoft Office Outlook and set it as the default mail client." I have it as the default email client. Also under the mail icon in control panel I have another profile that is {d9734f9-8cfb-411d-bc59-833e334fcb5e}. I can delete all the profiles and create just one profile that other profile comes back again. I have tried all the solutions that I have found in the net. I am using Windows Vista and Outlook 2007. Thanks Ed is this a home or...

Error message when replying to email
I connect remotely via dial-up VPN connection and able to receive emails, so the server connection is OK. I was able to send emails to both an inside and outside email, however when I reply to certain emails, I receive an error message "Network Problems are preventing connection to the microsoft exchange server". I am running W2k and Outlook 2000 and the server is Exchange 5.5. Any help would be appreciated. ...

Interaction between outlook and external application
Hi everybody, I know that this could not be the proper newsgroup, but I had no answer from dotnet.general... I'm programming an application (using Visual C# .NET) that has to create a .zip file, open a "compose new message" window in the default e-mail client application and automatically attach the .zip file to the message. Everything works perfectly if the default e-mail client is Outlook Express (or Netscape Mail), while an error occurs if the client is Outlook. (I've tried Outlook2000 and Outlook2003). After some testing I found out that the problem is related t...

The ol' "An object could not be found." message when trying to close a PST
As noted in the subject, I'm getting this message when trying to close my "Archived Folders" PST file. My searches using the KB as well as Google turned up a few instances of this message, but none had to do with closing a PST file. I've tried: - Renaming the "Archived Folders" PST, then re-opening OL2002. - Moving the "Archived Folders" PST to another directory, then re-opening OL2002. - Creating a new PST, copying everything from the archive PST into the new one, compacting the new one, and substituting it for the original "Archived Fol...

link error #5
Hi, After I change the project setting to 'multithreaded DLL' I got the link errors: uafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___wargv uafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc Is there any lib missing? thanks, chi ...

Email Errors> no download of messages>error messages. #2
Email Errors> no download of messages>error messages. My email has been working just fine until today. I can't think of anything I've done to create a problem. I'm using WindowsXP-pro-sp2; Outlook 2003, and Norton AntiVirus 2005. The same problem just started in Outlook Express as well. Was on the phone with Charter for over two hours removing email accounts and then adding them from scratch. I've been trying for hours and hours fix this to no avail--the error message keeps coming up and I'm expecting some very important email. The error messages will say someth...

Cannot access office out, getting POP3 Reporting Error 0X80042108
Hi there, i understand MS made some changes and now i am locked out from my MS Office Outlook. I get a POP3 Reporting Error # 0X80042108. The server does not recognize me. Is there any instructions on how to set or re-set this? Is there any REAL PERSON i can talk to for FREE Tech Support??? Thanks, Ray @ manauto@msn.com The changes were to how Outlook pulls Hotmail. Verify your settings against this: http://support.microsoft.com/kb/813514/en-us "Ray" <Ray@discussions.microsoft.com> wrote in message news:23A6252E-7B5F-454D-BB5A-5C9AB2B24DCD@microsoft.com... > Hi there...

Outlook Error #42
I keep getting the following error when I startup the application. "Microsoft Outlook; Error in registry for Exchange Extensions;?"The sintax format of the registry entry is incorrect. Check the registry settings and compare the registry for this extension to other extensions in the registry. Then the ok button displays. What could be causing this, and what's the solution. Thanks in advance Denise You might try searching for and deleting the extend.dat file while Outlook is closed, and see if that solves the problem. The file may be in a hidden folder, so make sure you ...

Error ID 1016 (Network Compromise)
I've been going through my event logs, and starting two days ago, I've seen domain users showing up in Error ID 1016 with the following message: domain\username has logged on to domain\username's mailbox and is not the Primary WinNT account. It would suggest that someone is reading someone else's mail. However, it's rampant- I'm receiving the error from multiple users accessing multiple mailboxes. It does not coincide with a backup and I've never seen the message prior to two days ago? What on earth is this? Additionally, I had a strong password (just changed it)...

Application.HyperLink vs controlname.HyperlinkAddress
Any comments on the use of one or the other in a form that opens a linked file? or on other methods like fHandleFile by Dev Ashish? Reason I ask: I need to make some changes in a database originally created in Access 2, then upgraded to '97 then upsized to a SQL server back end, and the front end upgraded to Access 2003. A lot of the code is archaic. some behaves erratically. -- Bob Quintal PA is y I've altered my email address. ...

Error Opening Reports Node on New Installation.
We had a pretty uneventful CRM installation, the product installed on the first attempt with no errors, and all aspects of it appear to operate correctly with the exception of Reports. When opening the reports node in CRM, we were getting the ever so useful "An Error has occurred, please contact your system administrator". I enabled verbose error messages in the web.config file and captured the followng error message. ========= Microsoft CRM Unhandled Error Details: Server Error in '/' Application. --------------------------------------------------------------------...

Outlook 2000 error #17
I cannot seem to keep Outlook open on our server. Dr. Watson comes up and says: An application error has occurred and an application error log is being generated. OUTLOOK.EXE Exception: access violation (0xc0000005) Address: 0x3f99a142 What in the world is that and what can I do about it? Thank you! Hello, The problem you are experiencing is most likely caused by some add-ins in Outlook. Try the following troubleshooting steps to narrow down the problem: Note: Since some anti-virus programs will cause unexpected application conflicts, please temporarily disable any anti-virus programs o...

Deplyment of MFC application
Hi, I have built a package for an MFC apllication in VC 2005 using following steps 1.From the Project menu, select Add and click File. 2.Find the folder that contains MyApplication.exe and MyLibrary.DLL and select them both. 3.In the File System window, right-click on Application Folder, point to Add and click Create to create a new folder. Call it MyLibrary. 4.Click on Application Folder again, select MyLibrary.DLL and drag it to the MyLibrary folder.In Solution Explorer, under your project in Detect Dependencies you should see that the Visual Studio detects dependencies on MFC90....

Some question about Application Domain
Hi! This is some text from book professional C# 2005. "Application domain are an extremely useful construct if assemblies are loaded dynamically, and the requirement exists to unload assemblies after use. Within the primary application domain it is not possible to get rid of loaded assemblies. However, it is possible to end application domain where all assemblies loaded just within the application domain are cleaned from the memory." The text say in one part "Within the primary application domain it is not possible to get rid of loaded assemblies" but I mean i...