Word Automation

K

KC8DCN

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

Doug Robbins - Word MVP

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top