My First Publisher Macro: ThisDocument Object

A

Alcide

Hello All,

I am working on a Macro to delete double spaces on a Publisher Document. The
Macro is below (shamelessly copied from Microsoft's help site, with minor
changes).

Option Explicit

Dim objDocument As ThisDocument

Sub KillDblSpaces()


For Each objDocument In ThisDocument
With objDocument.Find
.Clear
.MatchCase = True
.FindText = "^w^w"
.ReplaceWithText = "^w"
.ReplaceScope = pbReplaceScopeAll
.Execute
End With
Next objDocument
End Sub


It compiles but doesn't work. I get the following error:

"Object doesn't support this property or method"

I suspect that I am misapplying the ThisDocument object. Any ideas on this?

Thanks in advance for your support.
 
E

Ed Bennett

Alcide said:
I am working on a Macro to delete double spaces on a Publisher
Document. The Macro is below (shamelessly copied from Microsoft's
help site, with minor changes).

ThisDocument is not a collection, so you can't use a For Each on it.

You just want to apply code to ThisDocument, rather than each objDocument in
ThisDocument.
See the lines that are commented out, and the extra line added in.

Option Explicit

'Dim objDocument As ThisDocument

'Sub KillDblSpaces()


'For Each objDocument In ThisDocument
' With objDocument.Find
With ThisDocument.Find
.Clear
.MatchCase = True
.FindText = "^w^w"
.ReplaceWithText = "^w"
.ReplaceScope = pbReplaceScopeAll
.Execute
End With
'Next objDocument
'End Sub

Looking at the help file, it has ^W in caps, rather than ^w.
Also, if it's just spaces you're looking for and not tab characters, it
would be easier just to use " " rather than "^W"
I'm not sure if Publisher can even handle a ^W in the replace field - I
think it may be find-only.
 

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