Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Formatting based rendering of quotes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Csaba Gabor - 20 Nov 2007 10:16 GMT
How can I set up Word so that when I am in a Courier New font section, and type a single or double quote at
the keyboard, it will use Ascii 39 (') or Ascii 34 ("), respectively?

Details:  I'm writing a document in word (Word 2003 on Win XP Pro) with the default Times New Roman, 12pt
formatting.  In some sections I am showing computer code, and for those sections I use Courier New, 10pt.

The problem is that when I type a single quote or a double quote in the code sections, they come out as ‘left
leaning’ or “right leaning quotes” (ie matched quotes), instead of the 'straight' "quotes" (Ascii 39 and Ascii
34) that code parsers understand.  And I'm getting sick of copying single/double quotes from prior code
sections and overpasting them.  Hence my question.

Csaba Gabor from Vienna

PS.  I originally sent this during the past weekend, evidently in the midst of the "MI5 posting attack" and my
Thunderbird newsreader showed it as sent, but it never showed up in the newsgroup.  Anyone know what the story
is on that?
DeanH - 20 Nov 2007 14:02 GMT
Quick Check: Insert, AutoText, AutoText, AutoFormat is "Straight Quotes" with
"smart quotes" selected. deselect if so.
If not and still occurs maybe try entering your requirements under the
AutoCorrect tab.
This is for 2003 and prior, not 2007.
Hope this helps.
DeanH

> How can I set up Word so that when I am in a Courier New font section, and type a single or double quote at
> the keyboard, it will use Ascii 39 (') or Ascii 34 ("), respectively?
[quoted text clipped - 12 lines]
> Thunderbird newsreader showed it as sent, but it never showed up in the newsgroup.  Anyone know what the story
> is on that?
Csaba Gabor - 20 Nov 2007 17:13 GMT
In the meantime, I figured out a solution to my question which works
quite nicely (with KeyBindings).  However, in going to check the settings
you referred to, I found that I could not get rid of my solution -
event explicitly clearing the KeyBindings.ClearAll and shutting down
Word was not sufficient.  I eventually had to remove the functions
that the KeyBindings hooked into, and when I replaced them, things
operated normally.

OK, first of all those settings were checked, and it was the
'Autoformat As You Type' tab that I had to uncheck to remove the
replacement of "Straight Quotes" with "Smart Quotes".  But the
fact is that I like Smart Quotes, except when I'm in a code
section.  Furthermore, I don't think I can gain the type of
functionality I'm after with AutoCorrect.

So here is the solution that I have.  It seems to be working
nicely, and I am so far quite pleased with it.  I put
the following code into a module within the document and have
to enable macros:
Tools \ Macros \ Security \ Trusted Publishers then set
Trust Access to Visual Basic Project
Also, to avoid getting asked each time I also had to select:
Tools \ Macros \ Security \ Security Level \ Low

Sub AutoOpen()
  Application.KeyBindings.ClearAll      'Spotty track record
  CustomizationContext = ThisDocument   'else goes to Normal.Dot
  KeyBindings.Add wdKeyCategoryMacro, "SQuote", wdKeySingleQuote
  KeyBindings.Add wdKeyCategoryMacro, "DQuote", _
                  BuildKeyCode(wdKeyShift, wdKeySingleQuote)
End Sub

Function rightSideTest(sel As Selection)
  'return true if sel follows a character after
  'which there should be a closing quote
  rightSideTest = sel.Start > 0
  If Not rightSideTest Then Exit Function
  ask = Asc(sel.Document.Range(sel.Start - 1, sel.Start).Text)
  If ask <= 27 Then
    rightSideTest = False
  ElseIf ask = Asc(" ") Then
    rightSideTest = False
  ElseIf ask = Asc("[") Then
    rightSideTest = False
  ElseIf ask = Asc("{") Then
    rightSideTest = False
  ElseIf ask = Asc("(") Then
    rightSideTest = False
  ElseIf ask = Asc("<") Then
    rightSideTest = False
  End If
End Function

Sub SQuote()
' Put in a right/left single quote except in Courier make it straight
  Dim newChar: newChar = "'"
  If Mid(Selection.Font.Name, 1, 7) <> "Courier" Then
    If rightSideTest(Selection) Then newChar = ChrW(8217) _
                                Else newChar = ChrW(8216)
  End If
  Selection.TypeText newChar
End Sub

Sub DQuote()
' Put in a right/left double quote except in Courier make it straight
  Dim newChar: newChar = """"
  If Mid(Selection.Font.Name, 1, 7) <> "Courier" Then
    If rightSideTest(Selection) Then newChar = ChrW(8221) _
                                Else newChar = ChrW(8220)
  End If
  Selection.TypeText newChar
End Sub

Csaba Gabor from Vienna

> Quick Check: Insert, AutoText, AutoText, AutoFormat is "Straight Quotes" with
> "smart quotes" selected. deselect if so.
[quoted text clipped - 20 lines]
>> Thunderbird newsreader showed it as sent, but it never showed up in the newsgroup.  Anyone know what the story
>> is on that?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.