Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Fri, 10 Oct 2008 11:27:15 -0700,    group: microsoft.public.word.vba.general        back       


Word Automation   
Hello,

I have a macro which pulls in text files into a Word document:

Sub MergeTextFiles()

    Documents.Add
    
    ChDir ("C:\Documents and Settings\User\My Documents")
    'Change the path above to point to the new text files
    
    myName = Dir("*.txt")
    
    While myName <> ""
        With Selection
            .InsertFile FileName:=myName, ConfirmConversions:=False
            .InsertParagraphAfter
            .InsertBreak Type:=wdSectionBreakNextPage
            .Collapse direction:=wdCollapseEnd
        End With
    myName = Dir()
    Wend
    
    MsgBox ("Done.")

End Sub

When one user runs the macro, it works just file.  However, when another 
tries to use it (on the same computer), I get a Run-time 5097 error.  I've 
searched around and tried editing Word to run under each user, I've deleted 
temp files to ensure enough space, etc., but I haven't figured anything out.  
Any suggestions?

Thanks.
date: Fri, 10 Oct 2008 11:27:15 -0700   author:   KC8DCN

Re: Word Automation   
You do not say what line of code is causing the error, but without looking 
up that error message, I would suspect that it is the command

ChDir ("C:\Documents and Settings\User\My Documents")

Instead of "hard-coding" the folder in that way, incorporate the code in the 
article:

"How to allow the user to browse to and select a folder" at:

http://www.word.mvps.org/FAQs/MacrosVBA/BrowsDialog.htm

-- 
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

"KC8DCN"  wrote in message 
news:51BC868F-221F-4017-BB53-6495AAE1813E@microsoft.com...
> Hello,
>
> I have a macro which pulls in text files into a Word document:
>
> Sub MergeTextFiles()
>
>    Documents.Add
>
>    ChDir ("C:\Documents and Settings\User\My Documents")
>    'Change the path above to point to the new text files
>
>    myName = Dir("*.txt")
>
>    While myName <> ""
>        With Selection
>            .InsertFile FileName:=myName, ConfirmConversions:=False
>            .InsertParagraphAfter
>            .InsertBreak Type:=wdSectionBreakNextPage
>            .Collapse direction:=wdCollapseEnd
>        End With
>    myName = Dir()
>    Wend
>
>    MsgBox ("Done.")
>
> End Sub
>
> When one user runs the macro, it works just file.  However, when another
> tries to use it (on the same computer), I get a Run-time 5097 error.  I've
> searched around and tried editing Word to run under each user, I've 
> deleted
> temp files to ensure enough space, etc., but I haven't figured anything 
> out.
> Any suggestions?
>
> Thanks.
date: Sat, 11 Oct 2008 07:29:37 +1000   author:   Doug Robbins - Word MVP

Re: Word Automation   
The line of code causing the issue is:

 .InsertFile FileName:=myName, ConfirmConversions:=False

When the function enters debugging mode, I can hit continue and it continues 
to insert the text files into the document.  It doesn't always stop on the 
same files, though.  It appears to stop on random files.  Initially, I 
thought that it was the name of the files, but I've ruled that out.

What baffles me is that one user can log onto the computer and it works just 
file for that user.  When another user logs on, it throws the error.  It 
initially worked just fine, but apparently IT added another user and did some 
other things.  It worked for the user that was just added, but stopped for 
the user's account that is existing.

"Doug Robbins - Word MVP" wrote:

> You do not say what line of code is causing the error, but without looking 
> up that error message, I would suspect that it is the command
> 
> ChDir ("C:\Documents and Settings\User\My Documents")
> 
> Instead of "hard-coding" the folder in that way, incorporate the code in the 
> article:
> 
> "How to allow the user to browse to and select a folder" at:
> 
> http://www.word.mvps.org/FAQs/MacrosVBA/BrowsDialog.htm
> 
> -- 
> 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
> 
> "KC8DCN"  wrote in message 
> news:51BC868F-221F-4017-BB53-6495AAE1813E@microsoft.com...
> > Hello,
> >
> > I have a macro which pulls in text files into a Word document:
> >
> > Sub MergeTextFiles()
> >
> >    Documents.Add
> >
> >    ChDir ("C:\Documents and Settings\User\My Documents")
> >    'Change the path above to point to the new text files
> >
> >    myName = Dir("*.txt")
> >
> >    While myName <> ""
> >        With Selection
> >            .InsertFile FileName:=myName, ConfirmConversions:=False
> >            .InsertParagraphAfter
> >            .InsertBreak Type:=wdSectionBreakNextPage
> >            .Collapse direction:=wdCollapseEnd
> >        End With
> >    myName = Dir()
> >    Wend
> >
> >    MsgBox ("Done.")
> >
> > End Sub
> >
> > When one user runs the macro, it works just file.  However, when another
> > tries to use it (on the same computer), I get a Run-time 5097 error.  I've
> > searched around and tried editing Word to run under each user, I've 
> > deleted
> > temp files to ensure enough space, etc., but I haven't figured anything 
> > out.
> > Any suggestions?
> >
> > Thanks. 
> 
> 
>
date: Sat, 11 Oct 2008 18:08:10 -0700   author:   KC8DCN

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us