PDA

View Full Version : Solved: Western encoding message



Nolanjt2
03-02-2010, 09:34 AM
I have an automated process that takes a text file from the mainframe and parses it out into separate documents. Most of the time it works just great. Sometimes when it opens the mainframe text file, I get a dialogue box that asks for the encoding (Western). I click OK and then it continues to process. I would like that encoding box not to come up. Is there any way to tell the process that the encoding is Western. here is my code:

Dim objWord As Word.Document
Set objWord = GetObject("\\LNIUTTUM01\ftp\cvic\letters.txt" , "Word.Document")

Any suggestions?

Thank you!

lucas
03-02-2010, 10:01 AM
You might try adding this before the import. Be sure to reset it afterwords though:

Application.DisplayAlerts = wdAlertsNone

Nolanjt2
03-02-2010, 11:08 AM
Thanks, Lucas. My code resides in MSAccess. I typically controll the Microsft suite of products, Acrobat and Attachmate all from MSAccess. I tried the code for stopping the MSAccess alerts and that didn't help. Thanks for the suggestion. I'll try it. Hopefully it will work just fine.

Nolanjt2
03-02-2010, 11:30 AM
Well, Lucas, my application didn't like that code. I have the Word 12.0 among my references. I get "method or datamember not found" compile error. I think I may need to start out the line of code with something other than "Application". My mind just isn't coming to my rescue on this one.

ZVI
03-04-2010, 04:12 PM
Hi,

If it is not too late (having look on post date) then you can use the code below as template.
Please pay attention on Encoding:=Western



' ZVI:2010-03-04 http://www.vbaexpress.com/forum/showthread.php?t=30828
Sub WordImportTxt()

Dim objWord As Object, objDoc As Object

Const MyFile = "\\LNIUTTUM01\ftp\cvic\letters.txt" ' <-- Change to suit
Const DOS = 866, Western = 1252

' Get/Create Word Application object using late binding method
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err <> 0 Then Set objWord = CreateObject("Word.Application"): Err.Clear

' Open MyFile
Set objDoc = objWord.Documents.Open(MyFile, Encoding:=Western)
If Err <> 0 Then MsgBox "Can't open: " & MyFile, vbExclamation: GoTo exit_
On Error GoTo 0

' Activate Microsoft Word window
objWord.Visible = True
objWord.Tasks("Microsoft Word").Activate

' ... Do something else ...

exit_:
' Release the memory
Set objDoc = Nothing
Set objWord = Nothing

End Sub

Regards,
Vladimir

Nolanjt2
03-04-2010, 05:37 PM
Thank you ZVI. That looks like it should work. I'll give it a try. If it does, I won't have to babysit this project everyday.

Nolanjt2
03-08-2010, 10:57 AM
Thanks again ZVI. I have now included the code you provided with minor changes into my application and it works great. Thank you soooo much!

ZVI
03-08-2010, 11:28 AM
Thanks again ZVI. I have now included the code you provided with minor changes into my application and it works great. Thank you soooo much!
I'm pleased that this has helped,
Cheers,
Vladimir :beerchug: