Solved

A challenging question for experts

Posted on 2002-07-03
7
207 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now