Problem with Office 2003 vba in Office 2007

8

82whiskey

Hi all,

I just learned today that our old vba scripts written in Office 2003
will not work in Office 2007 specifically the Application.FileSearch
command. I've been doing some reading here but I don't understand vba
well enough to figure this out so some help would be appreciated.
Below is a script designed to search a single directory for .doc files
and combine them into one doc file. I'm hoping there is a simple fix
to get the script to run.

Thanks in advance
Brian


Sub CompileDailyFax()
Dim i As Integer
'Macro created 05/25/00 by Brian Avila
Documents.Add
With Application.FileSearch
.LookIn = "N:\Daily Fax\"
'Put the name of the folder you want to search after the lookin
property
.FileName = "*.doc"
'.FileName = type of files you want to search for
.Execute

If .FoundFiles.Count > 0 Then

For i = 1 To .FoundFiles.Count
Selection.Collapse direction:=wdCollapseEnd
Selection.InsertFile .FoundFiles(i)
If i <> .FoundFiles.Count Then
Selection.InsertBreak Type:=wdSectionBreakNextPage
ActiveDocument.Fields.Update

End If
Next i
End If
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.02)
.BottomMargin = InchesToPoints(0.55)
.LeftMargin = InchesToPoints(0.7)
.RightMargin = InchesToPoints(0.7)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.2)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
End With
End Sub
 
D

dedawson

You don't say exactly what the problem is; but, one thing that does
stick out is that you're restricting the search to .doc (Word 2003)
files. You probably want to also allow .docx (Word 2007) files.
 
G

Graham Mayor

Looking at the macro - http://www.gmayor.com/Boiler.htm will do what that
macro does (apart from adding the formatting at the end - however if you
create a template with those settings and start from a document created from
that template, the formatting commands are superfluous.)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
8

82whiskey

Hi,

Thanks for your replies. The only issue with the current script is
that I now get a runt-time error 5111 on the "With
Application.FileSearch" line.

The rest of the formatting code is needed because each person creating
these documents may add their own specific formatting to the body of
their documents and this is the only way to control it. Without it as
soon as it comes across a line that's bold or underlined it spreads to
the entire compiled document.

I don't know if it's possible but the ideal situation would be to
either get the "With Application.FileSearch" command to work or find a
new command I can put in its place.

Thanks again
 
G

Graham Mayor

Application.filesearch does not work in Word 2007.
If you are not happy with the boiler add in which does exactly the same
thing, then grow your own version - see
Application.FileDialog(msoFileDialogFilePicker)
http://support.microsoft.com/kb/288543 (which works fine in Word 2007)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

You are welcome :)

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

Similar Threads

Macro to fix header 0
Page setup 14
Letterhead Macro 1
Using Excel VBA to Format Word Document 0
macro problems 0
Word macro help- formatting and printing 2
Script 2
Programming Re Document Save 2

Top