Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Translating PC characters into Word

Status
Not open for further replies.

webrabbit

MIS
Jan 31, 2003
1,059
0
0
US
I am starting Word from the command line:
Code:
START WINWORD \folder\sub_folder\XXX.TXT

XXX.TXT often has extended PC characters in it, such as accented letters or line-draw characters. Sometimes Word will ask for the proper conversion, other times it assumes some conversion which results in a gargage translation. Is thee any way to tell Word to enther use the PC-8 conversion or always ask for he proper conversion?

I tried renaming XXX.TXT to XXX.DAT, but Word apparently dosen't care. It will take either one and convert or ask seemingly at random.

It also doen't make any difference if I start Word, than open the .TXT (or .DAT) file.

O/s is Window XP Pro
Microsoft Word 2002
 
When Word starts, you can tell it to run a particular macro. If that macro is coded to open you file using the appropriate filter, you might be able to get it to open the file correctly. See:
Cheers
Paul Edstein
[MS MVP - Word]
 
Well, no. Word knows how to do what I want, and sometimes does it. I just would like it always to do so.
 
>Word knows how to do what I want

Well, no, not really. What Word does is to analyse a chunk of text to try and see what it might be. The results of that analysis very much depend on the content of the text analysed, and sometimes Word gets it wrong.

Unfortunately there is no way to change the recognition algorith (well, there's a registry key setting that changes the size of the piece of text that will be analysed, but it is still subject to error), and there is no way in a simple text file to tell Word the specific encoding used (you can use a BOM to clarify which UTF scheme is being used, but not which code page).

So macropod's solution is about the only viable one.

Problem is that you want to pass a filename to the macro, and technically Word doesn't let you do that, so you have to resort to the API. Here's one version. Add this code to Normal.dot

Code:
[blue]Private Declare Function GetCommandLineW Lib "kernel32" () As Long
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long

Sub OpenMSDOS()
    Dim myFile As String
    myFile = Split(Split(PointerToStringW(GetCommandLineW), "/b")(1), " ")(0)

    Documents.Open FileName:=myFile, ConfirmConversions:=False, ReadOnly:= _
        False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
        "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
        Format:=wdOpenFormatAuto, XMLTransform:="", Encoding:=850
End Sub

Public Function PointerToStringW(lpStringW As Long) As String
     Dim buffer() As Byte
     Dim nLen As Long
     
    If lpStringW Then
         nLen = lstrlenW(lpStringW) * 2
         If nLen Then
             ReDim buffer(0 To (nLen - 1)) As Byte
             CopyMem buffer(0), ByVal lpStringW, nLen
             PointerToStringW = buffer
         End If
     End If
 End Function[/blue]

And then, using your preferred commandline:

[tt]start winword.exe /bd:\temp\test.txt /mOpenMSDOS[/tt]

Note the /b before the filename. This is flag that is unused by Word, so we can hijack it to pass the required filename to our macro
 
Although I've been working with computers since 1965 and have been using Word for about a decade, I know very little about its internal workings, and almost nothing about scripts. So, the question is, how do I get the above script into NORMAL.DOT?

(It was not long ago that I learned that NORMAL.DOT even existed.)
 
Sorry missed that at the end of your post. So, Office XP then
 
I guess so. When I click on Help and select Amout, I get Word 2002 with a long number after it. If you want, I could post that number.
 
Sorry didn't get back on this before now. Did you figure Normal.dot out?
 
No, I don'tk now how to edit Normal.Dot. And if I did, I wouldn't know where to put the script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top