Macro for combining Word documents into one —converting PC macro

B

banjotan

Version: 2004 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel Hi everyone,

I was looking for a way to combine multiple Word documents into a single document without copying and pasting or using the "Insert File" command.

I found a macro online (here: http://www.gaebler.com/How-to-Combine-Multiple-Word-Documents-Into-One-Document.htm), and I adjusted it a bit so it would work on a Mac, but it doesn't seem to work for me.

I'm hoping there's a macro expert out there who'd be willing to troubleshoot it.

Here's the macro:

Sub combine_docs()
'
' combine_docs Macro
' Macro created 5/4/10 by Jonathan Wichmann
'
Dim rng As Range
    Dim MainDoc As Document
    Dim strFile As String
    Const strFolder = "Hard Drive:Users:jonathanwichmann:Desktop:SSZ-to-typeset" 'change to suit
    Set MainDoc = Documents.Add
    strFile = Dir$(strFolder & "*.doc") ' can change to .docx
    Do Until strFile = ""
        Set rng = MainDoc.Range
        rng.Collapse wdCollapseEnd
        rng.InsertFile strFolder & strFile
        strFile = Dir$()
    Loop
End Sub

Thank you so much in advance!

Jonathan
 
J

John McGhie

Hi Jonathan:

You can't use wildcards in the Dir function on a Mac. Read the Word 2004
VBA Help topic "Dir Function" for more.

The theory is that you should use the Mac ID as a parameter tot he Dir
function. That would be:

Dir(strFolder, MacID("WDBN"))

But you're screwed, because OS 10.6 has dropped Type and Creator codes, and
even if it hadn't, a .docx is NOT a WDBN.

If I were you, I would create an "Input Folder" and simply make sure the
only files it creates are the ones you want. Much simpler...

In future when asking for help with code, you must say "what happens".
Saying "it doesn't work" is likely to invite the response "And this is our
problem because...???" in here :)

You don't need the dollar sign at the end of Dir: that function can return
ONLY a string.

You need to be aware that Dir can return a file list in random sequence: if
the sequence matters to you, you may need to load the results into an array
and sort them.

VBA can't sort arrays: but there's a WordBasic "SortArray" command you can
call that will.

Now you have done all this work, you were aware that if you simply select a
list of files in the Finder and drag them into a blank Word document, Word
will do all this for you? Just checking... There are times when you may
want to intervene during the process, in which case you need the macro. But
for a straight concatenation, just drag them in...

Hope this helps


Version: 2004 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel Hi
everyone,

I was looking for a way to combine multiple Word documents into a single
document without copying and pasting or using the "Insert File" command.

I found a macro online (here:
http://www.gaebler.com/How-to-Combine-Multiple-Word-Documents-Into-One-Documen
t.htm), and I adjusted it a bit so it would work on a Mac, but it doesn't seem
to work for me.

I'm hoping there's a macro expert out there who'd be willing to troubleshoot
it.

Here's the macro:

Sub combine_docs()
'
' combine_docs Macro
' Macro created 5/4/10 by Jonathan Wichmann
'
Dim rng As Range
Dim MainDoc As Document
Dim strFile As String
Const strFolder = "Hard
Drive:Users:jonathanwichmann:Desktop:SSZ-to-typeset" 'change to suit
Set MainDoc = Documents.Add
strFile = Dir$(strFolder & "*.doc") ' can change to .docx
Do Until strFile = ""
Set rng = MainDoc.Range
rng.Collapse wdCollapseEnd
rng.InsertFile strFolder & strFile
strFile = Dir$()
Loop
End Sub

Thank you so much in advance!

Jonathan

--

The email below is my business email -- Please do not email me about forum
matters unless I ask you to; or unless you intend to pay!

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410 | mailto:[email protected]
 
B

banjotan

Hi John,

Thank you so much for laying out this macro's problems for me and helping me avoid the same forum faux pas in the future.

I'm embarrassed to say I didn't realize you can drag files into a blank Word document to insert them. When I tried to concatenate them by selecting multiple files and dragging them into a blank document, it only inserted the first file. But maybe that's what you meant — dragging each file in order. If it should work differently, perhaps I'm doing something wrong. But even dragging them one by one will save time for me, so thank you!

Jonathan
--
Jonathan Wichmann
Editorial Assistant
New World Library
 

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