How to stop Word 2007 changing smart quotes in field

C

cayce

When I run a macro and input the word User’s in a field, the result has a
straight quote for the apostrophe. Why it presents this way, I do not know. I
fix this by using find/replace. However, if I subsequently run another
unrelated macro in the file, it resets this field back to a straight quote.

In Proofing options, on the Autoformat As You Type tab, I have selected
Replace “Straight Quotes†with “Smart Quotes.†I also have this flag set on
the Autoformat Tab.

Does anyone know how I can prevent this?
 
J

Jean-Guy Marcil

cayce said:
When I run a macro and input the word User’s in a field, the result has a
straight quote for the apostrophe. Why it presents this way, I do not know. I
fix this by using find/replace. However, if I subsequently run another
unrelated macro in the file, it resets this field back to a straight quote.

In Proofing options, on the Autoformat As You Type tab, I have selected
Replace “Straight Quotes†with “Smart Quotes.†I also have this flag set on
the Autoformat Tab.

Post the code you use to insert the field.
 
C

cayce

Jean-Guy:

I did not author the macros (I'm clueless about Visual basic). The specfic
macro in this issue is the HK_changeProjectName. In case it's relevant, I am
pasting below all the code used in our macros.

Thanks for the digging on this weirdness. I have not encountered this before.




'NOTES:
'
'Make sure that everything under the References folder is a valid
document/template.
'If there are any other files referenced, copy all the macros to a text
file, delete the macros here, save the document, reopen and then paste the
macros back in.
'That should reset any corrupted references.
'Also check under Tools->Templates and Add-Ins to make sure the only the
Normal template is being loaded.
'

'Updates the given text field with a value from the user
Private Sub changeTextField(msg As String, propName As String)
Dim userInput As String

'get user input
userInput = InputBox(msg)

'change doc property
ActiveDocument.CustomDocumentProperties(propName).Value = userInput
End Sub

'Updates the given date field with a valid date from the user
Private Sub changeDateField(msg As String, propName As String)
Dim userInput As Variant

'get user input
Do
userInput = InputBox(msg)
Loop While Not (IsDate(userInput))

'change doc property
ActiveDocument.CustomDocumentProperties(propName).Value =
Format(userInput, "mmmm d, yyyy")
End Sub

'make sure all fields in the document have the most current value
Private Sub updateFields()
Dim aStory As Range
Dim nextStory As Range

'update the fields in each document area type (story)
For Each aStory In ActiveDocument.StoryRanges
'since StoryRanges only returns the first Story of each type...
'...we need to make sure we check all the Stories of this type
Set nextStory = aStory
Do
nextStory.Fields.Update
Set nextStory = nextStory.NextStoryRange
Loop While Not (nextStory Is Nothing)
Next aStory
End Sub

'Gets new project name
Public Sub HK_changeProjectName()
changeTextField "Please enter new project name:", "HK_ProjName"
updateFields
End Sub

'Gets new customer name and updates
Public Sub HK_changeCustomerName()
changeTextField "Please enter new customer name:", "HK_CustName"
updateFields
End Sub

'Gets new customer name and updates
Public Sub HK_changeProposalNumber()
changeTextField "Please enter new proposal number:", "HK_PropNumber"
updateFields
End Sub

'Gets new publish date and updates
Public Sub HK_changePublishDate()
changeDateField "Please enter new publish date. Use the following
format: mm/dd/yyyy", "HK_PubDate"
updateFields
End Sub

'Gets new rev number and updates
Public Sub HK_changeRevisionNumber()
changeTextField "Please enter new revision number. Use the following
format: x.x", "HK_Rev"
updateFields
End Sub

'Gets new values and updates Project Name, Customer Name, Proposal Number
and Publish Date custom fields
Public Sub HK_changeAllFields()
changeTextField "Please enter new project name:", "HK_ProjName"
changeTextField "Please enter new customer name:", "HK_CustName"
changeTextField "Please enter new proposal number:", "HK_PropNumber"
changeDateField "Please enter new publish date. Use the following
format: mm/dd/yyyy", "HK_PubDate"

updateFields
End Sub

'Updates the leading character on all the heading list styles (HK Header
Level #)
Public Sub HK_UpdateHeadingNumbering()
Dim headingLevels As ListLevels
Dim currentLevel As ListLevel
Dim toc As TableOfContents
Set headingLevels = ActiveDocument.Styles("HK Heading
1").ListTemplate.ListLevels

Dim newPrefix As String
Dim newStartAt As Integer
Dim existingFormat As String
Dim firstPercent As Long

newPrefix = InputBox("Please enter the new heading letter prefix:")
newStartAt = InputBox("Please enter the new heading starting number:")

For Each currentLevel In headingLevels
firstPercent = InStr(currentLevel.NumberFormat, "%") - 1
existingFormat = Right(currentLevel.NumberFormat,
(Len(currentLevel.NumberFormat) - firstPercent))
currentLevel.NumberFormat = newPrefix & existingFormat
If currentLevel.Index = 1 Then
currentLevel.StartAt = newStartAt
Else
currentLevel.StartAt = 1
End If

Next currentLevel

For Each toc In ActiveDocument.TablesOfContents
toc.Update
Next toc

End Sub
 
G

Graham Mayor

Smart quotes are not substituted in dialog boxes however you can force it to
do so e.g.

userInput = Replace(InputBox(Msg), Chr(39), Chr(146))
in place of
userInput = InputBox(msg)

Private Sub changeTextField(msg As String, propName As String)
Dim userInput As String
'get user input
userInput = Replace(InputBox(Msg), Chr(39), Chr(146))
'change doc property
ActiveDocument.CustomDocumentProperties(propName).Value = userInput
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
C

cayce

Many thanks Graham. This works!!!

Graham Mayor said:
Smart quotes are not substituted in dialog boxes however you can force it to
do so e.g.

userInput = Replace(InputBox(Msg), Chr(39), Chr(146))
in place of
userInput = InputBox(msg)

Private Sub changeTextField(msg As String, propName As String)
Dim userInput As String
'get user input
userInput = Replace(InputBox(Msg), Chr(39), Chr(146))
'change doc property
ActiveDocument.CustomDocumentProperties(propName).Value = userInput
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

You are welcome :)

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


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

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