E
Edward Mendelson
Hello,
This is a question about a macro in which all the good ideas were offered by
Helmut Weber in answer to questions that I posted here in earlier threads.
Thanks to Helmut, I have a Word macro that helps fix a problem with
WordPerfect 5.1 documents imported into Word 2002 - but so far, the macro
works only with the main story in a document - not with the footnotes and
headers, etc. Can anyone help with this last part of the problem?
Here is the background: When Word 2002 opens a WordPerfect 5.1 document with
typographical symbols such as curly quotation marks and em or en dashes, or
some non-English alphabetical characters like the "oe" ligature, these
symbols are not converted into native Windows characters, but are stored as
invisible symbols. Helmut showed me how to devise a macro that replaces
these symbols, and the code is at the foot of the message.
I found this page has example code for making a find/replace operation work
through an entire document, but I have not been able to adapt it to work
with the kind of operation in this macro:
http://word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm
Can anyone help adapt it to the needs of this macro? Many thanks for any
advice.
Here is the code of the macro that works in the main story: Cut on the
dotted line:
-----------------------------------------------------------
Sub ChangeWPCharactersToNativeWindowsCharacters
Set dlg = Dialogs(wdDialogInsertSymbol)
FirstOccasion = True
Dim rDcm As Range
Dim oChr As Object
Dim sFnt As String ' font name
Dim iFnt As Integer ' character number
' for the following lines to work correctly, insert a form anywhere
' in the VBA project - simply use Insert/User Form, and then
' press Ctrl-F4 to close the form
Dim oDat As DataObject
Set oDat = New DataObject
Set rDcm = ActiveDocument.Range
For Each oChr In rDcm.Characters
If Asc(oChr) = 40 Then
' applies to most (or all) decorative fonts?
oChr.Select
' If Asc(Selection.Text) <> iAsc Then
' from previous posting would fit in here
' plus select case
SendKeys "%f^c{ESC}{ESC}" ' English version
dlg.Display
iFnt = Dialogs(wdDialogInsertSymbol).charnum
oDat.GetFromClipboard
sFnt = oDat.GetText
' for determining font name when adding changes
' MsgBox (sFnt)
' Debug.Print sFnt, iFnt
' change for WP TypographicSymbols font only
' fill in more characters later
If sFnt = "WP TypographicSymbols" Then
If Asc(Selection.Text) <> iFnt Then
Select Case iFnt
Case 64: Selection.TypeText Text:=Chr$(148) 'closing curly quote
Case 65: Selection.TypeText Text:=Chr$(147) 'opening curly quote
Case 66: Selection.TypeText Text:=Chr$(45) 'en dash
Case 67: Selection.TypeText Text:=Chr$(150) 'em dash
End Select
End If
End If
' change for Multinational Ext font only
' fill in more characters later
If sFnt = "Multinational Ext" Then
If Asc(Selection.Text) <> iFnt Then
Select Case iFnt
Case -3951: Selection.TypeText Text:=Chr$(156) 'oe ligature
End Select
End If
End If
' insert changes for other WP fonts here
End If
Next
End Sub
This is a question about a macro in which all the good ideas were offered by
Helmut Weber in answer to questions that I posted here in earlier threads.
Thanks to Helmut, I have a Word macro that helps fix a problem with
WordPerfect 5.1 documents imported into Word 2002 - but so far, the macro
works only with the main story in a document - not with the footnotes and
headers, etc. Can anyone help with this last part of the problem?
Here is the background: When Word 2002 opens a WordPerfect 5.1 document with
typographical symbols such as curly quotation marks and em or en dashes, or
some non-English alphabetical characters like the "oe" ligature, these
symbols are not converted into native Windows characters, but are stored as
invisible symbols. Helmut showed me how to devise a macro that replaces
these symbols, and the code is at the foot of the message.
I found this page has example code for making a find/replace operation work
through an entire document, but I have not been able to adapt it to work
with the kind of operation in this macro:
http://word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm
Can anyone help adapt it to the needs of this macro? Many thanks for any
advice.
Here is the code of the macro that works in the main story: Cut on the
dotted line:
-----------------------------------------------------------
Sub ChangeWPCharactersToNativeWindowsCharacters
Set dlg = Dialogs(wdDialogInsertSymbol)
FirstOccasion = True
Dim rDcm As Range
Dim oChr As Object
Dim sFnt As String ' font name
Dim iFnt As Integer ' character number
' for the following lines to work correctly, insert a form anywhere
' in the VBA project - simply use Insert/User Form, and then
' press Ctrl-F4 to close the form
Dim oDat As DataObject
Set oDat = New DataObject
Set rDcm = ActiveDocument.Range
For Each oChr In rDcm.Characters
If Asc(oChr) = 40 Then
' applies to most (or all) decorative fonts?
oChr.Select
' If Asc(Selection.Text) <> iAsc Then
' from previous posting would fit in here
' plus select case
SendKeys "%f^c{ESC}{ESC}" ' English version
dlg.Display
iFnt = Dialogs(wdDialogInsertSymbol).charnum
oDat.GetFromClipboard
sFnt = oDat.GetText
' for determining font name when adding changes
' MsgBox (sFnt)
' Debug.Print sFnt, iFnt
' change for WP TypographicSymbols font only
' fill in more characters later
If sFnt = "WP TypographicSymbols" Then
If Asc(Selection.Text) <> iFnt Then
Select Case iFnt
Case 64: Selection.TypeText Text:=Chr$(148) 'closing curly quote
Case 65: Selection.TypeText Text:=Chr$(147) 'opening curly quote
Case 66: Selection.TypeText Text:=Chr$(45) 'en dash
Case 67: Selection.TypeText Text:=Chr$(150) 'em dash
End Select
End If
End If
' change for Multinational Ext font only
' fill in more characters later
If sFnt = "Multinational Ext" Then
If Asc(Selection.Text) <> iFnt Then
Select Case iFnt
Case -3951: Selection.TypeText Text:=Chr$(156) 'oe ligature
End Select
End If
End If
' insert changes for other WP fonts here
End If
Next
End Sub