Share via

Question mark in find and replace Macro

Anonymous
2015-04-01T15:15:26+00:00

I am busy creating a macro, what I want is that the macro delete a space before a question mark, without changing the lay-out.

The problem is that a question mark in Publisher automatically is being converted to a wildcard. How can I prevent this in Publisher?

(I tried to use MatchWildecard like in Word but this doesn't work in Publisher)

my code:

 Function RepText(SFind As String, sRep As String)

    With Selection.ShapeRange.TextFrame.TextRange.Find

        .FindText = " ?"

        .MatchCase = False

        .ReplaceWithText = "? "

        .Forward = True

        .MatchWholeWord = False

        .ReplaceScope = pbReplaceScopeAll

        .Execute

    End With

End Function

Microsoft 365 and Office | Install, redeem, activate | For home | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

John Korchok 232.8K Reputation points Volunteer Moderator
2015-04-08T18:24:25+00:00

Give this a try:

.FindText = " " + "^063"

Was this answer helpful?

0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Anonymous
    2015-04-07T18:23:21+00:00

    if i use your code, some random letters are changed by the macro into question marks and thats exactly the problem what we are trying to solve.... any ideas how we can avoid this?

    Was this answer helpful?

    0 comments No comments
  2. John Korchok 232.8K Reputation points Volunteer Moderator
    2015-04-07T15:24:40+00:00

    Your previous macro required that you select each text box to search. This searches the entire document and replaces all instances:

    Sub ReplaceText()

      With ThisDocument.Find

        .FindText = " " + Chr(63)

        .MatchCase = False

        .ReplaceWithText = Chr(63) + " "

        .Forward = True

        .MatchWholeWord = True

        .ReplaceScope = pbReplaceScopeAll

        .Execute

      End With

    End Sub

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-04-07T11:34:25+00:00

    We have tried this methode before but the replace function keeps seeing the question mark as a wildcard as the sRep ans sFind are remainders of a previous trial

    Was this answer helpful?

    0 comments No comments
  4. John Korchok 232.8K Reputation points Volunteer Moderator
    2015-04-01T16:53:13+00:00

    Try substituting Chr(63) for the question mark:

    .FindText = " " + Chr(63)

    .ReplaceWithText = Chr(63) + " "

    But you have other issues here. You've written it as a function but are using it like a sub. Neither of the parameters passed to the function (SFind and sRep) are used in the code.

    Was this answer helpful?

    0 comments No comments