|
| Søg og Erstat som Batch/Macro i Word Fra : Brian Ibsen |
Dato : 14-12-00 15:18 |
|
Hejsa..
Nogen der ved hvordan jeg let laver en "søg og erstat" funkion på 800
dokumenter ???
På forhånd tak.
Brian Ibsen
| |
Per Andersen (14-12-2000)
| Kommentar Fra : Per Andersen |
Dato : 14-12-00 19:06 |
|
Blad tilbage i denne gruppe, hvor der ligger en henvisning
--
Mvh.
Per Andersen
Korrekt mail-addr: slavic@ (plus)image.dk
"Brian Ibsen" <flyinghigh@mailme.dk> wrote in message
news:91al0m$2l9k$1@news.cybercity.dk...
> Hejsa..
>
> Nogen der ved hvordan jeg let laver en "søg og erstat" funkion på 800
> dokumenter ???
>
> På forhånd tak.
>
> Brian Ibsen
>
>
| |
Brian Ibsen (14-12-2000)
| Kommentar Fra : Brian Ibsen |
Dato : 14-12-00 23:50 |
|
Ahh ja..jeg fandt noget godt......meeeen jeg kan ikke rigtig få det helt til
at virke....nogen der kan gennemskue problemet..
Den kode jeg prøver at bruge ser sådan her ud:
----------------------------------------------------------------------------
------
Option Explicit
Public Sub BatchReplaceAll()
Dim FirstLoop As Boolean
Dim myFile As String
Dim myDoc As Document
Dim Response As Long
'Error handler to handle error generated whenever
'the FindReplace dialog is closed
On Error Resume Next
'Close all open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges
'Boolean expression to test whether first loop
'This is used so that the FindReplace dialog will
'only be displayed for the first document
FirstLoop = True
'Set the directory and type of file to batch process
Dim i As Long
With Application.FileSearch
. NewSearch
.LookIn = "C:\Test\"
.SearchSubFolders = True
.FileName = "*.doc"
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
'Open document
Set myDoc = Documents.Open(.FoundFiles(i),)
If FirstLoop Then
'display dialog on first loop only
Dialogs(wdDialogEditReplace).Show
FirstLoop = False
Response = MsgBox("Do you want to process " & _
"the rest of the files in this folder", vbYesNo)
If Response = vbNo Then Exit Sub
Else
'On subsequent loops (files), a ReplaceAll is
'executed with the original settings and without
'displaying the dialog box again
With Dialogs(wdDialogEditReplace)
.ReplaceAll = 1
.Execute
End With
End If
'Close the modified document after saving changes
myDoc.Close SaveChanges:=wdSaveChanges
End With
End Sub
----------------------------------------------------------------------------
------
Meeeen den brokker sig over denne linje: Set myDoc =
Documents.Open(.FoundFiles(i),)
"Per Andersen" <slxavxic@image.dk> wrote in message
news:X88_5.9808$0p2.515474@news000.worldonline.dk...
> Blad tilbage i denne gruppe, hvor der ligger en henvisning
>
> --
> Mvh.
> Per Andersen
> Korrekt mail-addr: slavic@ (plus)image.dk
>
>
> "Brian Ibsen" <flyinghigh@mailme.dk> wrote in message
> news:91al0m$2l9k$1@news.cybercity.dk...
> > Hejsa..
> >
> > Nogen der ved hvordan jeg let laver en "søg og erstat" funkion på 800
> > dokumenter ???
> >
> > På forhånd tak.
> >
> > Brian Ibsen
> >
> >
>
| |
Per Andersen (15-12-2000)
| Kommentar Fra : Per Andersen |
Dato : 15-12-00 19:24 |
|
Mon ikke der mangler oplysning om hvilken "lookin"-folder? Ellers spørg den
oprindelige spørger, som fik det i gang.
--
Mvh.
Per Andersen
"Brian Ibsen" <flyinghigh@mailme.dk> wrote in message
news:91bj04$21r3$1@news.cybercity.dk...
> Ahh ja..jeg fandt noget godt......meeeen jeg kan ikke rigtig få det helt til
> at virke....nogen der kan gennemskue problemet..
> Den kode jeg prøver at bruge ser sådan her ud:
>
> ----------------------------------------------------------------------------
> ------
> Option Explicit
>
> Public Sub BatchReplaceAll()
>
> Dim FirstLoop As Boolean
> Dim myFile As String
> Dim myDoc As Document
> Dim Response As Long
>
> 'Error handler to handle error generated whenever
> 'the FindReplace dialog is closed
>
> On Error Resume Next
>
> 'Close all open documents before beginning
>
> Documents.Close SaveChanges:=wdPromptToSaveChanges
>
> 'Boolean expression to test whether first loop
> 'This is used so that the FindReplace dialog will
> 'only be displayed for the first document
>
> FirstLoop = True
>
> 'Set the directory and type of file to batch process
>
> Dim i As Long
>
> With Application.FileSearch
> . NewSearch
> .LookIn = "C:\Test\"
> .SearchSubFolders = True
> .FileName = "*.doc"
> .MatchTextExactly = True
> .FileType = msoFileTypeAllFiles
>
> If .Execute() > 0 Then
> For i = 1 To .FoundFiles.Count
>
> 'Open document
> Set myDoc = Documents.Open(.FoundFiles(i),)
>
> If FirstLoop Then
>
> 'display dialog on first loop only
>
> Dialogs(wdDialogEditReplace).Show
>
> FirstLoop = False
>
> Response = MsgBox("Do you want to process " & _
> "the rest of the files in this folder", vbYesNo)
> If Response = vbNo Then Exit Sub
>
> Else
>
> 'On subsequent loops (files), a ReplaceAll is
> 'executed with the original settings and without
> 'displaying the dialog box again
>
> With Dialogs(wdDialogEditReplace)
> .ReplaceAll = 1
> .Execute
> End With
>
> End If
>
> 'Close the modified document after saving changes
>
> myDoc.Close SaveChanges:=wdSaveChanges
>
> End With
>
> End Sub
> ----------------------------------------------------------------------------
> ------
>
>
>
> Meeeen den brokker sig over denne linje: Set myDoc =
> Documents.Open(.FoundFiles(i),)
>
>
>
> "Per Andersen" <slxavxic@image.dk> wrote in message
> news:X88_5.9808$0p2.515474@news000.worldonline.dk...
> > Blad tilbage i denne gruppe, hvor der ligger en henvisning
> >
> > --
> > Mvh.
> > Per Andersen
> > Korrekt mail-addr: slavic@ (plus)image.dk
> >
> >
> > "Brian Ibsen" <flyinghigh@mailme.dk> wrote in message
> > news:91al0m$2l9k$1@news.cybercity.dk...
> > > Hejsa..
> > >
> > > Nogen der ved hvordan jeg let laver en "søg og erstat" funkion på 800
> > > dokumenter ???
> > >
> > > På forhånd tak.
> > >
> > > Brian Ibsen
> > >
> > >
> >
>
>
| |
Per Andersen (16-12-2000)
| Kommentar Fra : Per Andersen |
Dato : 16-12-00 20:25 |
|
Det var netop det der var galt.
Tog lige et tjek. Rutinen virker - om ikke elegant - så dog effektivt. Men
sørg for, at der ikke er programkode i folderen.
Per Andersen
"Per Andersen" <slxavxic@image.dk> wrote in message
news:vlt_5.11114$0p2.581938@news000.worldonline.dk...
> Mon ikke der mangler oplysning om hvilken "lookin"-folder? Ellers spørg den
> oprindelige spørger, som fik det i gang.
>
> --
> Mvh.
> Per Andersen
>
> "Brian Ibsen" <flyinghigh@mailme.dk> wrote in message
> news:91bj04$21r3$1@news.cybercity.dk...
> > Ahh ja..jeg fandt noget godt......meeeen jeg kan ikke rigtig få det helt
til
> > at virke....nogen der kan gennemskue problemet..
> > Den kode jeg prøver at bruge ser sådan her ud:
> >
>
> ----------------------------------------------------------------------------
> > ------
> > Option Explicit
> >
> > Public Sub BatchReplaceAll()
> >
> > Dim FirstLoop As Boolean
> > Dim myFile As String
> > Dim myDoc As Document
> > Dim Response As Long
> >
> > 'Error handler to handle error generated whenever
> > 'the FindReplace dialog is closed
> >
> > On Error Resume Next
> >
> > 'Close all open documents before beginning
> >
> > Documents.Close SaveChanges:=wdPromptToSaveChanges
> >
> > 'Boolean expression to test whether first loop
> > 'This is used so that the FindReplace dialog will
> > 'only be displayed for the first document
> >
> > FirstLoop = True
> >
> > 'Set the directory and type of file to batch process
> >
> > Dim i As Long
> >
> > With Application.FileSearch
> > . NewSearch
> > .LookIn = "C:\Test\"
> > .SearchSubFolders = True
> > .FileName = "*.doc"
> > .MatchTextExactly = True
> > .FileType = msoFileTypeAllFiles
> >
> > If .Execute() > 0 Then
> > For i = 1 To .FoundFiles.Count
> >
> > 'Open document
> > Set myDoc = Documents.Open(.FoundFiles(i),)
> >
> > If FirstLoop Then
> >
> > 'display dialog on first loop only
> >
> > Dialogs(wdDialogEditReplace).Show
> >
> > FirstLoop = False
> >
> > Response = MsgBox("Do you want to process " & _
> > "the rest of the files in this folder", vbYesNo)
> > If Response = vbNo Then Exit Sub
> >
> > Else
> >
> > 'On subsequent loops (files), a ReplaceAll is
> > 'executed with the original settings and without
> > 'displaying the dialog box again
> >
> > With Dialogs(wdDialogEditReplace)
> > .ReplaceAll = 1
> > .Execute
> > End With
> >
> > End If
> >
> > 'Close the modified document after saving changes
> >
> > myDoc.Close SaveChanges:=wdSaveChanges
> >
> > End With
> >
> > End Sub
>
> ----------------------------------------------------------------------------
> > ------
> >
> >
> >
> > Meeeen den brokker sig over denne linje: Set myDoc =
> > Documents.Open(.FoundFiles(i),)
> >
> >
> >
> > "Per Andersen" <slxavxic@image.dk> wrote in message
> > news:X88_5.9808$0p2.515474@news000.worldonline.dk...
> > > Blad tilbage i denne gruppe, hvor der ligger en henvisning
> > >
> > > --
> > > Mvh.
> > > Per Andersen
> > > Korrekt mail-addr: slavic@ (plus)image.dk
> > >
> > >
> > > "Brian Ibsen" <flyinghigh@mailme.dk> wrote in message
> > > news:91al0m$2l9k$1@news.cybercity.dk...
> > > > Hejsa..
> > > >
> > > > Nogen der ved hvordan jeg let laver en "søg og erstat" funkion på 800
> > > > dokumenter ???
> > > >
> > > > På forhånd tak.
> > > >
> > > > Brian Ibsen
> > > >
> > > >
> > >
> >
> >
>
| |
|
|