Runtime errors 5097 and 5941

Discussion in 'Word VBA' started by KC8DCN, Oct 16, 2008.

  1. KC8DCN

    KC8DCN Guest


    I have macros that automate the process of inserting a folder full of files
    into a Word document, creating a new document, searching on specific
    criteria, and inserting the documents that meet the critieria into the new
    document (the text files are separated by section breaks). Here is my issue.

    The macros were originally created under a specific user name and worked
    without problems. The IT department added a user to the computer and I'm not
    exactly sure what else, but now there are problems. Some of the functions do
    not work under the original user name but work under the new name created.
    I'm baffled as to why some would work under one name and not the other,
    especially, when they worked fine under the original user.

    I am receiving a runtime error 5097 with this part of a function:
    With Selection
    .InsertFile FileName:=myName, ConfirmConversions:=False
    <-----the debugger stops on this line. It stops on random files each time it
    is ran.
    .InsertBreak Type:=wdSectionBreakNextPage
    .Collapse direction:=wdCollapseEnd
    End With

    This function works on the new user name but not the original user.

    On the following, I am receiving a runtime 5941 error ("The requested member
    of the collection does not exist"):
    Windows("document1.docx").Activate <---Debugger stops on this
    Selection.PasteAndFormat (wdPasteDefault)
    Selection.EndKey unit:=wdStory
    ActiveWindow.ActivePane.SmallScroll down:=-50

    For the above, both documents are open at the time of running. This does
    not work under the new user name but works under the prior user name. (The
    document name in quotes is changed to reflect document names and extensions
    showing/not showing.)

    I have searched high and low for answers and have tried various fixes to no
    avail. The IT department has told me that the only thing that they have done
    is added a user. I'm just short of trying to uninstall and reinstall Office
    2007 to see if that may fix the issues.

    Any ideas would be greatly appreciated. Thanks.
    KC8DCN, Oct 16, 2008
    1. Advertisements

  2. For the first error, you should look at the code that must be loading
    something into the variable myName.

    For the second, you should declare a Document object and set that to the
    document that you are expecting to be Document1.docx and then when you want
    to activate that document, activate the document object.

    Hope this helps.

    Please reply to the newsgroup unless you wish to avail yourself of my
    services on a paid consulting basis.

    Doug Robbins - Word MVP
    Doug Robbins - Word MVP, Oct 17, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.