WORD 2007 macro error

C

Chris Letts

I have several WORD 2003 macros.

Now I'm trying out WORD 2007, I find that some of these no longer work - the
macro statements return ' error 5111 - this command is not available '.

example statement is: With Application.FileSearch

FileSearch is still listed as a valid Application property on the help
pages. Have some of these been removed or disabled ?
 
Z

zkid

Would you please provide the full chunk of code?

We need to see what it is that you're attempting to accomplish,

In the meantime, I seem to recall that I had trouble with
Application.FileSearch in VBA 2003 but not in XP, so I substituted the
following code in its place. I'm REALLY shortcutting it here with a message
box so you can see how it works. Of course, you would need to substitute
your code to either fill an array or list box, depending on what you're
attempting to do with it:

Dim myFile, strFolder As String, iCount As Integer

'Due to the way 2007 names files, you need to keep the asterisk after the
extension. This will also work in all other versions of Word (after 95, that
is).

strFolder = "c:\TheFolderToSearch\*.doc*" 'For all files, use *.*.

iCount = 0

myFile = Dir$(strFolder)
Do While myFile <> ""
iCount = iCount + 1
MsgBox myFile
myFile = Dir$
Loop

If iCount = 0 Then MsgBox "No Word files were found in the following
location: " & strFolder
 
C

Chris Letts

yes I can easily substitue new code - that's not the point though - it means
I have to re-write many existing macros. The help pages say that these SHOULD
work, but they don't.

here is some code (which works fine in WORD 2003):


Sub insert_pic()
'
' insert_pic Macro
' Macro recorded 27/09/2006 by Administrator
'
Dim student As String

With Application.FileSearch
.NewSearch
.LookIn = "E:\speech"
.SearchSubFolders = False
.FileName = "*.jpg"


If .Execute() > 0 Then

For i = 1 To .FoundFiles.Count

Selection.InlineShapes.AddPicture FileName:=.FoundFiles(i),
LinkToFile:=False, SaveWithDocument:=True

student = .FoundFiles(i)
howlong1 = Len(.LookIn)
howlong2 = Len(student)


student = Right$(student, howlong2 - howlong1 - 1)
howlong2 = Len(student)
student = Left$(student, howlong2 - 4)


Selection.TypeText Text:=student

Selection.MoveRight Unit:=wdCell

Next i
Else
MsgBox "There were no files found."
End If
End With



End Sub
 
C

Cindy M.

Hi =?Utf-8?B?Q2hyaXMgTGV0dHM=?=,

FileSearch is definitely being removed from Office 2007. The reasoning is that
file searching is part of the Operating System (Vista) and doesn't belong in
individual applications. The old "Dir" command should still work.
I have several WORD 2003 macros.

Now I'm trying out WORD 2007, I find that some of these no longer work - the
macro statements return ' error 5111 - this command is not available '.

example statement is: With Application.FileSearch

FileSearch is still listed as a valid Application property on the help
pages. Have some of these been removed or disabled ?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
C

Chris Letts

I guessed as much, however the help pages need updating - they still list
that as a valid function.......
 

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