Solved

insert file

Posted on 2003-11-21
10
743 Views
Last Modified: 2012-08-14
hi
I want to insert *.txt file to word document using VBA without ConfirmConversions

Sub Makro1()
     Selection.InsertFile FileName:="a2.txt", ConfirmConversions:=false
End Sub

The problem is:  Word sometimes interprets txt file (with txt extension) as HTML document.
For example, if file wherever contain string "<table>" word will interpred file as HTML (no matter that file is without </table> <html>, but if file contains <h2> gfghjfjreeee </h2> it is interpreted as text.)

So, I want to force Word to interprete any file with .txt extension as text without using ConfirmConversions:=true.




0
Comment
Question by:jsemenak
10 Comments
 
LVL 37

Expert Comment

by:Joanne M. Orzech
Comment Utility
What version of Word?
0
 
LVL 9

Author Comment

by:jsemenak
Comment Utility
Word 2000
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
Comment Utility
Under Tools, Options, General - is "confirm conversion at open" unchecked?  If so you shouldn't even need the ConfirmConversions code.
0
 
LVL 9

Author Comment

by:jsemenak
Comment Utility
Problem is not with ConfirmConversions
I can state in VBA for do or don't do it.
I want to have ConfirmConversions = false, It is not problem.

Problem is  that word sometimes intrepretes txt file (with *.txt extension) as html. So I want to use convertor for txt.
If I select manualy from ConfirmConversions dialog  -Only Text
I will get good result, but if I don't use confirmation word badlz intrerprete txt file as html.
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
Comment Utility
Not sure if I know how to do that without having the conversion box come up.  Will think about it.  In the meantime, maybe someone else here will be able to help you.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 37

Expert Comment

by:Joanne M. Orzech
Comment Utility
OK - I tried this - even with Tools, Options, Confirm Conversion at open to be true - this worked for me:

    Application.DisplayAlerts = wdAlertsNone
    Selection.InsertFile FileName:="yourfile", Range:="", _
        ConfirmConversions:=False, Link:=False, Attachment:=False

Hope it works for you too
0
 
LVL 9

Author Comment

by:jsemenak
Comment Utility
Steel not good.
Code with Application.DisplayAlerts = wdAlertsNone
or withou this work identicaly.

I have in my txt file named a.txt this:

vlozit
<table>
obr1

I want to get this, but  using  this I get

vlozit
obr1

where obr1 is in new created table, because of word using wrong file converter.

It is clear, that your code can't influance strange and stupid word intelligence which interpretes txt file as HTML (especially in case when contained text is not valid HTML code) Do you test your code for txt file containing string <table>?
In may computer this don't work correctly.

So I have to force word to use correct convertor for txt. This convertor have index1.
Fileconverters(1)
I must select this convertor without any manual work (because I want to insert a lot of txt files). The possible way is automatically choose first item from the list in confirmation dialog, but I do not know code for this and in InsertFile is not any parameter determining which converter has to be used.
 
If I will not find how to force Word to use convertor I have to use statment Open Read Close.



0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
Comment Utility
0
 
LVL 10

Expert Comment

by:daleoran
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ: No Refund

Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Daleoran
EE Cleanup Volunteer
0
 

Accepted Solution

by:
PashaMod earned 0 total points
Comment Utility
PAQed - no points refunded (of 100)

PashaMod
Community Support Moderator
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

762 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

13 Experts available now in Live!

Get 1:1 Help Now