FileObjects in transition from office2003 to office2007

M

Martin

Dear experts,

I have installed Office2007 on my PC and successfully imported the
normal.dot file, preserving all the macros. However, the functionality
Application.FileSearch ..
does apparently not work.
Does someone know, how to transport these FileObject functions to Word under
Office2007?

Thank you,
Martin
 
M

Martin

Thank you very much. I could make first steps indeed and got into the loop of
the files. However, after
While myFile <> ""
I cannot loop through all the files, it means the program only opens the
very first one and does not proceed to the next.
In Office2003 we had this row of commands, for instance,

With Application.FileSearch
For iFile = 1 To .FoundFiles.Count
Set CurrentFile = Documents.Open(.FoundFiles(iFile))
....
CurrentFile.Close SaveChanges:=wdNotSaveChanges
Next iFile
End With

and it is quite exactly, what I like to realise under O2007, but could not
so far. Handicapping is the fact, that the help-function in VBA under O2007
delivers answers relying on commands valid under O2003 only ('FileSearch'
etc. for example).
But maybe I am mistaken somewhere.

Thank you,
Martin
 
G

Graham Mayor

The loop routine is essentially that shown below. It works with both Word
2007 and 2003.

Dim strFile As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog
.Title = "Select Folder containing the documents to be modifed and click
OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With

If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
strFile = Dir$(strPath & "*.do?")

While strFile <> ""
Set oDoc = Documents.Open(strPath & strFile)

'*********************************
'Do what you want with the open file here
'*********************************

oDoc.Close SaveChanges:=wdSaveChanges
strFile = Dir$()
Wend


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

Martin

Thank you, it works very well.

Martin

Graham Mayor said:
The loop routine is essentially that shown below. It works with both Word
2007 and 2003.

Dim strFile As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog
.Title = "Select Folder containing the documents to be modifed and click
OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With

If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
strFile = Dir$(strPath & "*.do?")

While strFile <> ""
Set oDoc = Documents.Open(strPath & strFile)

'*********************************
'Do what you want with the open file here
'*********************************

oDoc.Close SaveChanges:=wdSaveChanges
strFile = Dir$()
Wend


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

Top