🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.vbasic
Article #104365

Re: [VBA] Word - usuwanie fragmentów tekstu zgodnie z wyrażeniem regularnym

#104365
From: jacki
Date: Tue, 27 Oct 2009 18:15
42 lines
2241 bytes
InDesign Scripts pisze:
>> Zatem zgaduję, że przy wywołaniu muszę ustawić ReplaceIn na cały 
>> dokument (jak?). ReplaceWhat sobie stworzę regexpa stosując (), aby 
>> móc zastosować $1 $2 itd. w ReplaceWith. Jak tylko to zrobić, aby 
>> przeszukał cały dokument?
> 
> nagraj sobie makro w WORDzie ;)

Chciałbym jednak napisać. Doszedłem do czegoś takiego (regexpa 
odpowiedniego sobie stworzę, tu tylko przykład):

Sub zmien()
'
' zmien Makro
'
'
     Const strTest As String = "cecha1: slowo1 cecha2: slowo2 "
     Const strWhat As String = "cecha1:\s+(\S+)\s+cecha2:\s+(\S+)\s+"
     Const strWith As String = "$1"

     MsgBox RegExpSubstitute(strTest, strWhat, strWith)

End Sub

Function RegExpSubstitute(ReplaceIn, ReplaceWhat As String, ReplaceWith 
As String)
     Dim RE As Object
     Set RE = CreateObject("vbscript.regexp")
     RE.Pattern = ReplaceWhat
     RE.Global = True
     RegExpSubstitute = RE.Replace(ReplaceIn, ReplaceWith)
End Function


Nie mam tylko pojęcia jak zamiast strTest podać cały dokument, oraz jak 
dokonać zmian w tym dokumencie (może też mi otworzyć nowy dokument i do 
niego wypluć wyjście) - testowo mam MsgBox.

-- 
Pozdrawiam
Andrzej Jackiewicz
jacki(at)idealan.pl
Technical Details
Message-ID: <hc7dce$hc6$1@news.task.gda.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.task.gda.pl!not-for-mail
References: <hc6et5$i0m$1@news.task.gda.pl> <hc6p0n$br4$1@news.task.gda.pl> <hc6uf8$c44$1@inews.gazeta.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.task.gda.pl!not-for-mail
From: jacki <collector@idealan.pl>
Newsgroups: pl.comp.lang.vbasic
Subject: Re: [VBA] Word - usuwanie fragmentów tekstu zgodnie
 z wyrażeniem regularnym
Date: Tue, 27 Oct 2009 19:15:47 +0100
Organization: CI TASK http://www.task.gda.pl/
Lines: 42
Message-ID: <hc7dce$hc6$1@news.task.gda.pl>
References: <hc6et5$i0m$1@news.task.gda.pl> <hc6p0n$br4$1@news.task.gda.pl> <hc6uf8$c44$1@inews.gazeta.pl>
NNTP-Posting-Host: jackimode.siec.idealan.pl
Mime-Version: 1.0
X-Trace: news.task.gda.pl 1256667342 17798 80.48.82.200 (27 Oct 2009 18:15:42 GMT)
X-Complaints-To: abuse@news.task.gda.pl
NNTP-Posting-Date: Tue, 27 Oct 2009 18:15:42 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
In-Reply-To: <hc6uf8$c44$1@inews.gazeta.pl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit