Saving a .txt file as .rtf ...

Guys,

For reasons I won't bore you with, my little Access VBA app needs to create 3 versions of a compiled 'string' based file ...

1. a .txt version
2. a HTML version
3. a .rtf version

No problems with 1 & 2 ... but the .rtf version is causing me a problem.

I'm compiling my string-based document and saving it using FSO ... cheekily just changing the extension ... but the .rft 'knows' it is not true .rft ... that is having a knock-on effect for what I am actually using this for (pre-designing Autosigs. in Outlook, if you are interested)

Anyone know how I can save a .txt file as 'real' .rft ??

Thanks,

S.S.
SpencerSteelAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rockiroadsConnect With a Mentor Commented:
ok, never giving up (well try not to) on a challenge
Ive been looking at how we can do conversions in VBA and Word Automation just clicked to me.
This code does depend on Word being installed, but then if u got MSAccess, there is a very high chance that word is installed

What I do is open txt file in Word, then save as RTF format

Public Sub Txt2RTF()

    Dim objWord As Object
    Dim objDoc As Object
   
   
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Open("c:\ee\dd.txt")
    objDoc.SaveAs "c:\ee\dd.rtf", 6
    objDoc.Close
    objWord.Quit
    Set objDoc = Nothing
    Set objWord = Nothing
   
End Sub



I have tested this on a couple of files and found it is producing a file with RTF tags
So this is my proposed solution.
I also use late binding so there is never a issue with references and different office versions!

0
 
Jonathan KellyCommented:
if you save the file as rtf rather than changing a txt extension - does that make a difference ?

maybe >> use ole to load it into word and save it as rtf


0
 
SpencerSteelAuthor Commented:
mmm ... thought this might be the solution ... anyone want to write the code for me for the 500 points, where "myString" is the body copy (sorry - really rushed here)

Cheers,

S.S.

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
wesbirdCommented:
Simple

Put the "Microsoft Rich Textbox Control 6 (SP6)" or whatever version you have on a hidden form.  Call it RTFEdit

Simply call it to convert txt to rtf like this:

RTFEdit.Text = txtPlainText
txtRTF = RTFEdit.TextRTF

e.g. input:

Use the Microsoft Rich Textbox Control

output:

{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang1033\f0\fs17 Use the Microsoft Rich Textbox Control
\par }

0
 
Richard DanekeTrainerCommented:
DoCmd.OutputTo ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart

Where ObjectType can be acOutputFunction or acOutputStoredProcedure and
where AcFormat can be one of these acFormatASP, acFormatHTML, acFormatRTF, or acFormatTXT

0
 
Richard DanekeTrainerCommented:
Your code to a function that constructs a string would be:

1. DoCmd.OutputTo acOutputFunction, "MyString", AcFormatTXT, ".\MyString", False
2. DoCmd.OutputTo acOutputFunction, "MyString", AcFormatHTML, ".\MyString", False   or
    DoCmd.OutputTo acOutputFunction, "MyString", AcFormatASP, ".\MyString", False
3. DoCmd.OutputTo acOutputFunction, "MyString", AcFormatRTF, ".\MyString", False
0
 
Richard DanekeTrainerCommented:
Oops, Function name needed not string variable....

1. DoCmd.OutputTo acOutputFunction, "funMyString", AcFormatTXT, ".\MyString", False
2. DoCmd.OutputTo acOutputFunction, "funMyString", AcFormatHTML, ".\MyString", False   or
    DoCmd.OutputTo acOutputFunction, "funMyString", AcFormatASP, ".\MyString", False
3. DoCmd.OutputTo acOutputFunction, "funMyString", AcFormatRTF, ".\MyString", False
0
 
rockiroadsCommented:
I was going to suggest you save your txt in a table, then output that using DoCmd.OutputTo

Now DoDahD has already given you the various options and so you don't have to worry about creating specific types
0
 
SpencerSteelAuthor Commented:
Thanks DoDahD - I like the idea but I'm a bit stuck

I've assigned this code to a blank form button ...

   DoCmd.OutputTo acOutputFunction, fnCreateString, acFormatRTF, ".\MyString", False

where fnCreateString (for test purposes is)

   Public Function fnCreateString()

   fnCreateString = "blah blah blah!"

   End Function

But on clicking the button, Access is saying that it "can't find the object 'blah blah blah'" ...

I've obviously missed the point on this. I thought the idea was to 'OutputTo' the result of the function ... whereas Access is just trying to output the entire function ... how does that work?

Thanks,

S.S.

0
 
SpencerSteelAuthor Commented:
*sigh* ... been playing around with outputting queries (looks ugly, can't get rid of field name) and reports (does that whole 'exporting to...' flashing box thing (not good enough)

I've very frustrating. Would like to know if the Function,Module thing might help.

Thanks,

S.S.
0
 
Richard DanekeTrainerCommented:
You are on the right track.

   Public Function fnCreateString()

   fnCreateString = "blah blah blah!"

   End Function
Redefines fnCreateString as "blah blah blah!"   The function needs to return a string.

   Public Function fnCreateString(strCreateString as String)

   Dim strCreateString as String
   strCreateString = "blah blah blah!"

   End Function

- D
0
 
SpencerSteelAuthor Commented:
Argh ! I must be really thick ... i'm still getting an error on the call ... what is wrong with this ?

---------

DoCmd.OutputTo acOutputFunction, fnCreateString(), acFormatRTF, "c:\test.rtf", False

----------

 Public Function fnCreateString()

  Dim strCreateString As String
   
   strCreateString = "blah blah blah!"

   End Function

--------

Thanks so much,

S.S.
0
 
Richard DanekeTrainerCommented:
S.S.
I, too, have had trouble using the acOutputFunction option.  I cannot find a good reference on its use.

Your string data is stored in a table? , query?, or what?

I have had good luck in testing with acOutputQuery and acOutputReport.  Is your string available in a different object?

- DD
0
 
Richard DanekeTrainerCommented:
BTW,
I created a table, a query, and a report.
The query and table add column headings, the report can be created w/out headers or footers and will format for appearance (fonts, sizes, positions).  
Let me know your progress...
0
 
Richard DanekeTrainerCommented:
S.S.
If you want to look at the database I was using follow this link:

Direct link to your file
https://filedb.experts-exchange.com/incoming/ee-stuff/240-EE-Test.zip 

The function trash was my attempt to follow my own advice  :-(

Leaving the filename option blank in OutputTo prompts for a filename.
0
 
rockiroadsCommented:
Have u tried linking your document to Access as a table?
File/Get External Data

then outputto that table to the various formats
0
 
Jeffrey CoachmanMIS LiasonCommented:
DoDahD,

Check this link, it has interesting info on what make a file an .rtf File.

http://www.experts-exchange.com/Databases/MS_Access/Q_21606146.html#15151642

Hope this helps as well
0
 
SpencerSteelAuthor Commented:
Hello Rockiroads,

You really don't give up, do you !

Sadly, I'm right slap-bang in the middle of an absolute nightmare of a (non-development) issue at the moment and am going to struggle to test this out right now, but I trust you!

I'm going to add it to my To Do list and make sure I check it out asap and award you your hard-earned points !

Just so you know I haven't disppeared into an EE blackhole

Thanks for caring :)

S.S.
0
 
rockiroadsCommented:
S.S.
No worries. Twas a good challenging question, one hopefully I have sorted for you.
Any problems let me know. I dont plan on going anywhere quite just yet, well perhaps next week, if and when I win the lottery :)

Miriam, is it okay to leave this question open a bit longer?
0
 
mbizupCommented:
No problem...

S.S.,  Just please follow up on this within the next 21 days so that we know that you are still interested in the question.

Thanks,

mbizup
EE Cleanup Volunteer


0
 
rockiroadsCommented:
thanks
0
 
SpencerSteelAuthor Commented:
Sorted ! We got there ... thanks Rockiroads, worked very well !
0
All Courses

From novice to tech pro — start learning today.