Solved

A challenging question for experts

Posted on 2002-07-03
7
212 Views
Last Modified: 2010-05-02
I have converted a pdf file containing japanese fonts to a text file. so when i open the text file it shows me junk in place of japanese character.

Now when i change the extension from txt to doc and open the file it asks me for encoding and i select UTF-8 and the page gets successfully opened.

now where i need your help is to automate this process of changing the extension name from txt to doc from my VB application and selecting UTF-8 encoding and reading the doc file.

Regards
A.Pandey
0
Comment
Question by:Amitabh
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 7128879
The first part is relatively simple:
Name oldpathname.txt As newpathname.doc

========================================
The second part requires you to create a word OLE automation object and then invoke the object's OPEN method, specifying the UTF-8 encoding as one of the parameters of the Open method.
0
 
LVL 5

Expert Comment

by:kcm76
ID: 7129190
** include project-references-micorsoftword9.0 object library.

** change the folder path in Open Statement


Dim docPolicy As Word.Document
Private Sub Command1_Click()
Set docPolicy = Documents.Open("c:\KCM\TEST.TXT")
With docPolicy
   .SaveAs FileName:="C:\kcm\test.doc"
   .Close
End With
Set docPolicy = Nothing
End Sub

ALL THE BEST
0
 

Author Comment

by:Amitabh
ID: 7131103
Its giving me error here
 Set docPolicy = Documents.Open("c:\xpdf\app.txt")

error is :
"Active X component can't create object"

i have checked for the path. also i know, i have to give UTF-8 encoding so how will i give it. open function provides encoding as optional argument.

Regards
A.Pandey

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 5

Accepted Solution

by:
kcm76 earned 100 total points
ID: 7131200
ya, i too got the same error, not the first time, but from second time onwards...

try this
**include project-references-micorsoftword9.0 object library

Dim docPolicy
Private Sub Command1_Click()
Set docPolicy = CreateObject("Word.Document")
Set docPolicy = Documents.Open("c:\KCM\TEST.TXT")
With docPolicy
  .Save
  .SaveAs FileName:="C:\kcm\test.doc"
  .Close
End With
Set docPolicy = Nothing
End Sub


0
 
LVL 18

Expert Comment

by:mdougan
ID: 7132032
Actually, you only need to include the reference to the word object library if you use the original syntax of:

Dim docPolicy As Word.Document

If you use the suggested syntax of:

Set docPolicy = CreateObject("Word.Document")

Then you don't need to specify the reference to the library.  I would recommend the latter, because if you set a reference to the library, you are picking a specific version of the Word object library, and, if the client doesn't have that specific version of Word, then they will get this same error.

0
 
LVL 18

Expert Comment

by:mdougan
ID: 7132055
As far as specifying the encoding, I think that it's one of the parameters in the open statement:

expression.Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible)

I'm not sure if you need to set the Format or the Encoding parameter, here is an example setting the Format parameter, I can't find any help on setting the Encoding parameter....

Set wrdDoc = wrdApp.Documents.Open("H:\Code\test.txt",,,,,,,,,wdOpenFormatEncodedText)
0
 

Author Comment

by:Amitabh
ID: 7136610
thanx all of you for your support.

createobject is working fine and mdougan thanx for telling us the reason.

Regards
A.Pandey
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question