Replace text

H

hans_enigma

Hello,

I'm using a VBA to change text whitin a document.

Sub verv()

Dim contents
If Not FrontPage.ActiveDocument Is Nothing Then
If FrontPage.ActivePageWindow.ViewMode < fpPageViewNormal Then
FrontPage.ActivePageWindow.ViewMode = fpPageViewNormal
End If
contents = ActiveDocument.all(0).innerHTML
contents = Replace(contents, "03-06-", "<br>03-06-", 1, -1,
vbTextCompare)
contents = Replace(contents, "27-11-", "<br>27-11-", 1, -1,
vbTextCompare)
ActiveDocument.all(0).innerHTML = contents
End If

End Sub

This works fine at the opened document.

Is it possible to use this script for example 25 document without openening
the documents?
 
G

Graham Mayor

You cannot run macros on documents without opening them. You can open and
close Word documents and process them whilst open with a batch processing
macro such as that below. You will undoubtedly have to modify it for your
purposes.

Sub BatchProcess()
Dim strFilename As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , _
"List Folder Contents"
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
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strFilename = Dir$(strPath & "*.doc")

While Len(strFilename) <> 0
Set oDoc = Documents.Open(strPath & strFilename)
'
'Do what you want with oDoc here
'
oDoc.Close SaveChanges:=wdSaveChanges
strFilename = Dir$()
Wend
End Sub



See also http://www.gmayor.com/batch_replace.htm

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