MS Word VB macro editor

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

Vi¹nja Antolkoviæ Iliæ

Hello everybody!
Is there some good soul which could help me with my problem?
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.

Thanks
 
A

Auric__

Hello everybody!
Is there some good soul which could help me with my problem?
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.

VBA in Word is not the same thing as VB.Net; it's essentially VB6 + various
MSOffice stuff. Further VBA/Word questions will probably get better replies
in microsoft.public.word.programming.

Having said that, this is a slightly brain-dead method which assumes that
*every* occurance of "#" is a delimiter:

Sub killSplats()
'variants, just in case it's a *really* big doc
Dim L0 As Variant, L1 As Variant, everything As String

With Selection
startOver:
.WholeStory
everything = .Text
For L0 = L1 + 1 To Len(everything)
If "#" = Mid(everything, L0, 1) Then
For L1 = L0 + 1 To Len(everything)
If "#" = Mid(everything, L1, 1) Then
.Start = L0 - 1
.End = L1
.Delete
L1 = L0
GoTo startOver 'gasp! teh eeeeeevile GOTO! :)
End If
Next
End If
Next
End With
End Sub

I *strongly* suggest you test this on non-production data *before* using it
for real.
 
V

Višnja Antolković Ilić

VBA in Word is not the same thing as VB.Net; it's essentially VB6 + various
MSOffice stuff. Further VBA/Word questions will probably get better replies
in microsoft.public.word.programming.

Having said that, this is a slightly brain-dead method which assumes that
*every* occurance of "#" is a delimiter:

    Sub killSplats()
        'variants, just in case it's a *really* big doc
        Dim L0 As Variant, L1 As Variant, everything As String

        With Selection
    startOver:
            .WholeStory
            everything = .Text
            For L0 = L1 + 1 To Len(everything)
                If "#" = Mid(everything, L0, 1) Then
                    For L1 = L0 + 1 To Len(everything)
                        If "#" = Mid(everything, L1, 1) Then
                            .Start = L0 - 1
                            .End = L1
                            .Delete
                            L1 = L0
                            GoTo startOver  'gasp! teh eeeeeevile GOTO! :)
                        End If
                    Next
                End If
            Next
        End With
    End Sub

I *strongly* suggest you test this on non-production data *before* using it
for real.

Hello!
this is great and it's working. It's just one thing left..
I have this sign - all over the text and this macro hasn't deleted it.
It has delete everyhing but this -
:)


Dim L0 As Variant
Dim L1 As Variant

Dim everything As String
Dim startOver As String


With Selection
startOver:
.WholeStory
everything = .Text
For L0 = L1 + 1 To Len(everything)
If "#" = Mid(everything, L0, 1) Then
For L1 = L0 + 1 To Len(everything)
If "#" = Mid(everything, L1, 1) Then
.Start = L0 - 1
.End = L1
.Delete
L1 = L0
GoTo startOver 'gasp! teh eeeeeevile
GOTO! :)
End If
Next
End If
Next
End With
End Sub
 
A

Auric__

Hello everybody!
Is there some good soul which could help me with my problem?
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.

VBA in Word is not the same thing as VB.Net; it's essentially VB6 +
various MSOffice stuff. Further VBA/Word questions will probably get
better replies in microsoft.public.word.programming.

Having said that, this is a slightly brain-dead method which assumes
that *every* occurance of "#" is a delimiter: [snip code]
I *strongly* suggest you test this on non-production data *before*
using it for real.

Hello!
this is great and it's working. It's just one thing left..
I have this sign - all over the text and this macro hasn't deleted it.
It has delete everyhing but this -
:)

If this doesn't do what you want, then you really, really need to ask in
the above-mentioned Word group (microsoft.public.word.programming).

Sub killSplats()
'variants, just in case it's a *really* big doc
Dim L0 As Variant, L1 As Variant, everything As String

With Selection
startOver:
.WholeStory
everything = .Text
For L0 = L1 + 1 To Len(everything)
If "#" = Mid(everything, L0, 1) Then
For L1 = L0 + 1 To Len(everything)
If "#" = Mid(everything, L1, 1) Then
If " - " = Mid(everything, L0 - 2, 1) Then
.Start = L0 - 4
ElseIf "- " = Mid(everything, L0 - 2, 1) Then
.Start = L0 - 3
Else
.Start = L0 - 1
End If
.End = L1
.Delete
L1 = L0
GoTo startOver 'gasp! teh eeeeeevile GOTO! :)
End If
Next
End If
Next
End With
End Sub
 
A

Auric__

On Fri, 27 Aug 2010 10:49:38 GMT, Vi¹nja Antolkoviæ Iliæ wrote:
Hello everybody!
Is there some good soul which could help me with my problem?
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.
VBA in Word is not the same thing as VB.Net; it's essentially VB6 +
various MSOffice stuff. Further VBA/Word questions will probably get
better replies in microsoft.public.word.programming.
Having said that, this is a slightly brain-dead method which assumes
that *every* occurance of "#" is a delimiter: [snip code]
I *strongly* suggest you test this on non-production data *before*
using it for real.
Hello!
this is great and it's working. It's just one thing left..
I have this sign - all over the text and this macro hasn't deleted
it. It has delete everyhing but this -
:)

If this doesn't do what you want, then you really, really need to ask
in the above-mentioned Word group (microsoft.public.word.programming). [snip code again]
- Prikaži citirani tekst -
I did ask microsoft.public.word.programming but they didn't give the
right answer neighter...

Try the second code I posted. It removes dashes from *before* the "#". If
that's not good enough, it's time for you to open your wallet and pay
someone to do it.
 

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