Macro to delet text from first appearance of #

  • Thread starter Vi¹nja Antolkoviæ Iliæ
  • Start date
V

Vi¹nja Antolkoviæ Iliæ

Hello everybody!

I have to write a macro in Word template which would delete all of
the
text which starts with # and ends with #.
I'm uselles with VB - any help would be appreciated.

Thanks
 
G

Graham Mayor

Dim sFindText As String
Dim oRng As Range
sFindText = "#*#"
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = sFindText
Do While .Execute(Forward:=True, MatchWildcards:=True) = True
oRng.Delete
Loop
End With

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
V

Vi¹nja Antolkoviæ Iliæ

Dim sFindText As String
Dim oRng As Range
sFindText = "#*#"
Set oRng = ActiveDocument.Range
With oRng.Find
    .Text = sFindText
    Do While .Execute(Forward:=True, MatchWildcards:=True) = True
        oRng.Delete
    Loop
End With

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>







- Prikaži citirani tekst -

Hello!
Thanks for the macro. Wel it deletes only # sign and it leaves
everything else.
The tekst wich I need to delete looks like this:
1.#koz# 1234568 - #skozm#
2.#kozm# 23564 - #skozm#
3.#kozm# 22542 - #skozm#
4.#kozm# 88165 - #skozm#

numbers after #kozm# are changing but I have to delete them too.
 
G

Graham Mayor

'*' is something of a blunt instrument - if the sequences are all lower case
letters, then change the macro to

Dim sFindText As String
Dim oRng As Range
sFindText = "#[a-z]{1,}#"
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = sFindText
Do While .Execute(Forward:=True, MatchWildcards:=True) = True
oRng.Delete
Loop
End With

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

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Dim sFindText As String
Dim oRng As Range
sFindText = "#*#"
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = sFindText
Do While .Execute(Forward:=True, MatchWildcards:=True) = True
oRng.Delete
Loop
End With

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

message





- Prikazi citirani tekst -

Hello!
Thanks for the macro. Wel it deletes only # sign and it leaves
everything else.
The tekst wich I need to delete looks like this:
1.#koz# 1234568 - #skozm#
2.#kozm# 23564 - #skozm#
3.#kozm# 22542 - #skozm#
4.#kozm# 88165 - #skozm#

numbers after #kozm# are changing but I have to delete them too.
 
V

Vi¹nja Antolkoviæ Iliæ

'*' is something of a blunt instrument - if the sequences are all lower case
letters, then change the macro to

Dim sFindText As String
Dim oRng As Range
sFindText = "#[a-z]{1,}#"
Set oRng = ActiveDocument.Range
With oRng.Find
    .Text = sFindText
    Do While .Execute(Forward:=True, MatchWildcards:=True) = True
        oRng.Delete
    Loop
End With

See alsohttp://www.gmayor.com/replace_using_wildcards.htm

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Dim sFindText As String
Dim oRng As Range
sFindText = "#*#"
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = sFindText
Do While .Execute(Forward:=True, MatchWildcards:=True) = True
oRng.Delete
Loop
End With
My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
messagenews:6dcd10dc-0006-4cfa-8cce-adeac28c8a9a@z28g2000yqh.googlegroups.com...
- Prikazi citirani tekst -

Hello!
Thanks for the macro. Wel it deletes only # sign and it leaves
everything else.
The tekst wich I need to delete looks like this:
1.#koz# 1234568 - #skozm#
2.#kozm# 23564 - #skozm#
3.#kozm# 22542 - #skozm#
4.#kozm# 88165 - #skozm#

numbers after #kozm# are changing but I have to delete them too.- Sakrij citirani tekst -

- Prika¾i citirani tekst -

error 5560
something to do with sFindText = "#[a-z]{1,}#"
 
G

Graham Mayor

If locally you use a semi colon as separator character you would need to
change that to
sFindText = "#[a-z]{1;}#"

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


error 5560
something to do with sFindText = "#[a-z]{1,}#"
 
V

Višnja Antolković Ilić

If locally you use a semi colon as separator character you would need to
change that to
sFindText = "#[a-z]{1;}#"

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


error 5560
something to do with sFindText = "#[a-z]{1,}#"

nope
it doesn't do anything at all now
stays still
 
G

Graham Mayor

Check Windows Regional settings and see what the list separator character is
for your language version and replace the semi colon with that character.
If that doesn't make it work, send me a copy of your document (or a section
of it) to the link on the home page of my web site.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



If locally you use a semi colon as separator character you would need to
change that to
sFindText = "#[a-z]{1;}#"

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

message
error 5560
something to do with sFindText = "#[a-z]{1,}#"

nope
it doesn't do anything at all now
stays still
 
V

Višnja Antolković Ilić

Check Windows Regional settings and see what the list separator characteris
for your language version and replace the semi colon with that character.
If that doesn't make it work, send me a copy of your document (or a section
of it) to the link on the home page of my web site.

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

If locally you use a semi colon as separator character you would need to
change that to
sFindText = "#[a-z]{1;}#"
My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
messagenews:725201da-c04d-4d04-87f1-1eb117a54bd1@y11g2000yqm.googlegroups.com...
error 5560
something to do with sFindText = "#[a-z]{1,}#"

nope
it doesn't do anything at all now
stays still- Sakrij citirani tekst -

- Prikaži citirani tekst -

there's an error on the link to your home page
 

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