Read rtf file in vba
-
- Administrator
- Posts: 79662
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Read rtf file in vba
Yes - if you open the .rtf file in Word, you'll see that it contains multiple sections.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 706
- Joined: 18 Jan 2022, 15:59
- Location: Re-routing rivers, in Hof, Beautiful Bavaria
Re: Read rtf file in vba
OK, thanks.
If I click on that strange music symbol , I do see some "abschnitt" (Section) thing as you indicated, but in my Words so far, there is no Section info, bottom left, … by default … but I can get it – right click in the blue stripe bit at the bottom and check the option for it Having a quick google says there is normally just one on a new document, so maybe that is why it was new to me. Sure enough I dug out a couple of my very longest word files and still only got… ( when looking at the html in a text editor of a document of a version saved as .htm ) ..just a single
<div class=WordSection1>
Maybe the 1 should have sparked my curiosity before.
Sounds like it’s not to do with some sort of forced on you thing, like a page. Something perhaps you might want to do perhaps to have different formatted sections. Probably ends up a more efficient and controlled way to do that instead of just selecting a whole chunk and applying format to it, perhaps.
( In the particular sample file, sample.rtf , it would appear that the page number corresponds to the same section number, coincidence or design, I have no idea )
I expect my limited use of word means I will likely never need it myself. I’ll quit quickly while I am ahead, before someone wants to inform me of some formatting style possibilities or such, Lol, and wait to, and hope to, have more time later to delve deeper into Word things. I’m still busy enough scratching the surface of Excel and Excel VBA
But I will know to watch out for more than one Section, when messing with documents I didn't create.
If I click on that strange music symbol , I do see some "abschnitt" (Section) thing as you indicated, but in my Words so far, there is no Section info, bottom left, … by default … but I can get it – right click in the blue stripe bit at the bottom and check the option for it Having a quick google says there is normally just one on a new document, so maybe that is why it was new to me. Sure enough I dug out a couple of my very longest word files and still only got… ( when looking at the html in a text editor of a document of a version saved as .htm ) ..just a single
<div class=WordSection1>
Maybe the 1 should have sparked my curiosity before.
Sounds like it’s not to do with some sort of forced on you thing, like a page. Something perhaps you might want to do perhaps to have different formatted sections. Probably ends up a more efficient and controlled way to do that instead of just selecting a whole chunk and applying format to it, perhaps.
( In the particular sample file, sample.rtf , it would appear that the page number corresponds to the same section number, coincidence or design, I have no idea )
I expect my limited use of word means I will likely never need it myself. I’ll quit quickly while I am ahead, before someone wants to inform me of some formatting style possibilities or such, Lol, and wait to, and hope to, have more time later to delve deeper into Word things. I’m still busy enough scratching the surface of Excel and Excel VBA
But I will know to watch out for more than one Section, when messing with documents I didn't create.
You do not have the required permissions to view the files attached to this post.
Last edited by DocAElstein on 03 May 2024, 06:32, edited 2 times in total.
Arnold: How did I get in here?
Taxi driver: The door opened, you got in.
Taxi driver: The door opened, you got in.
-
- 5StarLounger
- Posts: 666
- Joined: 27 Jun 2021, 10:46
Re: Read rtf file in vba
> I expect Input(LOF(1), 1) should be better Input(LOF(hFile), hFile) ? )
Yep. Mea culpa. Was trying to keep some of the OPs code, and forgot to update this bit. In this trivial example hFile happens to equal 1, so the code works - but it isn't best practice.
Yep. Mea culpa. Was trying to keep some of the OPs code, and forgot to update this bit. In this trivial example hFile happens to equal 1, so the code works - but it isn't best practice.
-
- 5StarLounger
- Posts: 666
- Joined: 27 Jun 2021, 10:46
Re: Read rtf file in vba
>But it’s just a very tiny part of the original
It has the same full content as the UFT One document (well, there are some very minor differences). It ijust it lacks some of the (useful) navigation aids (which admittedly is a poor thing to do; I absolutely agree with you that Microsoft's handling of old documentation/articles is poor)
It has the same full content as the UFT One document (well, there are some very minor differences). It ijust it lacks some of the (useful) navigation aids (which admittedly is a poor thing to do; I absolutely agree with you that Microsoft's handling of old documentation/articles is poor)
-
- 5StarLounger
- Posts: 706
- Joined: 18 Jan 2022, 15:59
- Location: Re-routing rivers, in Hof, Beautiful Bavaria
Re: Read rtf file in vba
. I am seeing it slightly differently now
, the redirect on the first link you gave
and the second link your gave
are both looking more similar.
I am fairly sure I went to just an introductory page when I first was redirected.
Something quirky is going on? – an intelligent redirect thing? Related to browser history or something else on a particular computer, IP address etc.
I have had this frustration before
Certainly I think you need to be careful with these links these days. I think perhaps we may possibly be seeing the start of where what and when you, or someone else, end up with can vary, and an organisation may be able to influence, for a price, what happens.
What is UFT One document?, wiki thinks UTF One started in 2019, and our original stuff seems to be from around the 2006 – 2008 time. If that is the case, then the UFT One document won’t necessarily be a good indication of the original content in this case
I still think, at first glance at least, I see more from the
(3rd party and original from wayback machine) ----- compared to the “newer” -------- (redirect or current)
I confess I have not read everything to see if its all there but just rearranged. That would take me a few weeks. It is not easy to make a quick comparison. But the "old" looks, on avarage, more
Pic is:-
--"Old" ------------------------------------------------------------------------------------------ "New"
, the redirect on the first link you gave
and the second link your gave
are both looking more similar.
I am fairly sure I went to just an introductory page when I first was redirected.
Something quirky is going on? – an intelligent redirect thing? Related to browser history or something else on a particular computer, IP address etc.
I have had this frustration before
Certainly I think you need to be careful with these links these days. I think perhaps we may possibly be seeing the start of where what and when you, or someone else, end up with can vary, and an organisation may be able to influence, for a price, what happens.
What is UFT One document?, wiki thinks UTF One started in 2019, and our original stuff seems to be from around the 2006 – 2008 time. If that is the case, then the UFT One document won’t necessarily be a good indication of the original content in this case
I still think, at first glance at least, I see more from the
(3rd party and original from wayback machine) ----- compared to the “newer” -------- (redirect or current)
I confess I have not read everything to see if its all there but just rearranged. That would take me a few weeks. It is not easy to make a quick comparison. But the "old" looks, on avarage, more
Pic is:-
--"Old" ------------------------------------------------------------------------------------------ "New"
You do not have the required permissions to view the files attached to this post.
Arnold: How did I get in here?
Taxi driver: The door opened, you got in.
Taxi driver: The door opened, you got in.
-
- 5StarLounger
- Posts: 666
- Joined: 27 Jun 2021, 10:46
Re: Read rtf file in vba
>UFT One
UFT One is the tool used by the 3rd party to display the document. The document is older than the tool., and is almost certainly extracted from an MSDN CD
UFT One is the tool used by the 3rd party to display the document. The document is older than the tool., and is almost certainly extracted from an MSDN CD
-
- 5StarLounger
- Posts: 706
- Joined: 18 Jan 2022, 15:59
- Location: Re-routing rivers, in Hof, Beautiful Bavaria
Re: Read rtf file in vba
Ok, thanks, I thought maybe that, - It says UTF One top left on that 3rd party page.
Extraction from an older CD or DVD would be my choice, and more so as time goes on. I think it shouldn't be like that, so I do understand when people disagree with me, but sadly, I think that is the reality we may not always like to admit sometimes
One way or another, things ( me at the least , Lol ), are getting lost in the redirects....
Extraction from an older CD or DVD would be my choice, and more so as time goes on. I think it shouldn't be like that, so I do understand when people disagree with me, but sadly, I think that is the reality we may not always like to admit sometimes
One way or another, things ( me at the least , Lol ), are getting lost in the redirects....
Arnold: How did I get in here?
Taxi driver: The door opened, you got in.
Taxi driver: The door opened, you got in.
-
- 5StarLounger
- Posts: 666
- Joined: 27 Jun 2021, 10:46
Re: Read rtf file in vba
Here's how it looks on the October 2001 MSDN CDs (a whichj were represented by a set of windows help files, CHMs)
You do not have the required permissions to view the files attached to this post.
-
- 5StarLounger
- Posts: 706
- Joined: 18 Jan 2022, 15:59
- Location: Re-routing rivers, in Hof, Beautiful Bavaria
Re: Read rtf file in vba
I like the look of that - nice to see it.
I was still sleeping in my self imposed technology coma as a hermit when those chm hlp winhlp things where around.
I like the format.
( a while back I got the things to work on newer computers from help here , https://eileenslounge.com/viewtopic.php ... 61#p281561 )
( I even made one once, …… but it was right at the beginning of my awakening, in some frenzy, I think, https://www.excelforum.com/excel-new-us ... ost4827570 - God, what was I on, when I wrote postings like that, Lol. Still living exclusively off those vegetables, maybe. )
I was still sleeping in my self imposed technology coma as a hermit when those chm hlp winhlp things where around.
I like the format.
( a while back I got the things to work on newer computers from help here , https://eileenslounge.com/viewtopic.php ... 61#p281561 )
( I even made one once, …… but it was right at the beginning of my awakening, in some frenzy, I think, https://www.excelforum.com/excel-new-us ... ost4827570 - God, what was I on, when I wrote postings like that, Lol. Still living exclusively off those vegetables, maybe. )
Arnold: How did I get in here?
Taxi driver: The door opened, you got in.
Taxi driver: The door opened, you got in.
-
- 5StarLounger
- Posts: 666
- Joined: 27 Jun 2021, 10:46
Re: Read rtf file in vba
As I am sure you are aware:
.hlp is an old type of help format based on a proprioetary mark up language created by Microsoft. They officially retired it upon the release of Vista (i.e no longer shipped support for it in the OS). After 'feedback' they grudgingly released winhlp32 for download for Vista, W7, W8 and W8.1 - but NO official version for W10 or W11. The W8/W8.1 version will work on W10 (and, I assume W11), but is a tricky to install correctly - me, I've never bothered)
.chm is the newer help file format, based off HTML, and was introduced in Windows 95, around about 10 years before .hlp was retired (so Microsoft gave plenty of warning that .hlp was going to disappear at some point). .chm remains fully supported across the WIndows OS family (and the MSDN CDs were chm)
.hlp is an old type of help format based on a proprioetary mark up language created by Microsoft. They officially retired it upon the release of Vista (i.e no longer shipped support for it in the OS). After 'feedback' they grudgingly released winhlp32 for download for Vista, W7, W8 and W8.1 - but NO official version for W10 or W11. The W8/W8.1 version will work on W10 (and, I assume W11), but is a tricky to install correctly - me, I've never bothered)
.chm is the newer help file format, based off HTML, and was introduced in Windows 95, around about 10 years before .hlp was retired (so Microsoft gave plenty of warning that .hlp was going to disappear at some point). .chm remains fully supported across the WIndows OS family (and the MSDN CDs were chm)
-
- 5StarLounger
- Posts: 706
- Joined: 18 Jan 2022, 15:59
- Location: Re-routing rivers, in Hof, Beautiful Bavaria
Re: Read rtf file in vba
Thanks,
I can’t remember how far I got in the full understanding of these things back then, but I go through my older War and Peace postings, when I am feeling brave and fit enough to read through them, and then I try to check, correct and sanitise them. I have made a note to check back here when I do that one, to make sure I am saying things right , and add the insights you give.
Alan
I can’t remember how far I got in the full understanding of these things back then, but I go through my older War and Peace postings, when I am feeling brave and fit enough to read through them, and then I try to check, correct and sanitise them. I have made a note to check back here when I do that one, to make sure I am saying things right , and add the insights you give.
Alan
Arnold: How did I get in here?
Taxi driver: The door opened, you got in.
Taxi driver: The door opened, you got in.
-
- NewLounger
- Posts: 4
- Joined: 23 Oct 2024, 16:27
Re: Read rtf file in vba
Hi All,
I am not a VBA programmer but helping dept. for an automation effort. I need to read in rtf file names (no need for content) and the creation dates into an Excel sheet. The code works perfect with C:\output\myfile.txt but not C:\output\myfile.rtf, it says can't find the file. I tried ProxieObj with InkEdit without success. Both program files and dataset files can be found without problems by exactly the same code.
Could anyone offer a quick fix?
Many thanks!
Frank
I am not a VBA programmer but helping dept. for an automation effort. I need to read in rtf file names (no need for content) and the creation dates into an Excel sheet. The code works perfect with C:\output\myfile.txt but not C:\output\myfile.rtf, it says can't find the file. I tried ProxieObj with InkEdit without success. Both program files and dataset files can be found without problems by exactly the same code.
Could anyone offer a quick fix?
Many thanks!
Frank
-
- Administrator
- Posts: 79662
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Read rtf file in vba
Welcome to Eileen's Lounge!
What is the code you're using now?
What is the code you're using now?
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 4
- Joined: 23 Oct 2024, 16:27
Re: Read rtf file in vba
Code: Select all
' Process rtf file
Range("H" + i).Select
rtffile = Range("H" + i)
Debug.Print "rtffile: " + rtffile
Debug.Print "Dir val: " + outdir + rtffile
Debug.Print "Dir: " + Dir(outdir + rtffile)
If Dir(outdir + rtffile) <> "" And rtffile <> "" Then
Debug.Print "Setting hyperlink: " + outdir + Hyperlink
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=outdir + rtffile, TextToDisplay:=rtffile
If Mid(FileDateTime(outdir + rtffile), 2, 1) <> "/" Then
'rtfdate = Mid(FileDateTime(outdir + rtffile), 1, 10)
rtfdate = FileDateTime(outdir + rtffile)
Debug.Print rtfdate
Range("L" + i).Value = rtfdate
Else
'rtfdate = Mid(FileDateTime(outdir + rtffile), 1, 9)
rtfdate = FileDateTime(outdir + rtffile)
Debug.Print rtfdate
Range("L" + i).Value = rtfdate
End If
End If
' Process Program file
Debug.Print pgmdir
Range("J" + i).Select
pgmfile = Range("J" + i)
test = pgmdir + pgmfile
Debug.Print "The value of test is " + test
If Dir(pgmdir + pgmfile) <> "" And pgmfile <> "" Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=pgmdir + pgmfile, TextToDisplay:=pgmfile
If Mid(FileDateTime(pgmdir + pgmfile), 2, 1) <> "/" Then
'pgmdate = Mid(FileDateTime(pgmdir + pgmfile), 1, 10)
pgmdate = FileDateTime(pgmdir + pgmfile)
Debug.Print pgmdate
Range("M" + i).Value = pgmdate
Else
'pgmdate = Mid(FileDateTime(pgmdir + pgmfile), 1, 9)
pgmdate = FileDateTime(pgmdir + pgmfile)
Debug.Print pgmdate
Range("M" + i).Value = pgmdate
End If
End If
Last edited by Leif on 25 Oct 2024, 05:08, edited 1 time in total.
Reason: To add [code] tags
Reason: To add [code] tags
-
- NewLounger
- Posts: 4
- Joined: 23 Oct 2024, 16:27
Re: Read rtf file in vba
the 'Process Program File is essentially the same as the 'Process rtf File, but rtfdate = FileDateTime(outdir + rtffile) just doesn't work. I tested the code in local C drive and it works fine with .txt file.
-
- Administrator
- Posts: 79662
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Read rtf file in vba
That is very strange. I ran the rtf part of your code using a .rtf file on my PC and it worked as intended: it created a valid hyperlink.
Are you sure that outdir and rtffile are spelled exactly correctly, and that outdir ends in a backslash?
Are you sure that outdir and rtffile are spelled exactly correctly, and that outdir ends in a backslash?
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 4
- Joined: 23 Oct 2024, 16:27
Re: Read rtf file in vba
Thanks Hans! This is encouraging. Is there any setting I need to have or turned on in order to run .rtf code successfully?
-
- Administrator
- Posts: 79662
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Read rtf file in vba
No, I suspect that there is a misspelling in outdir or rtffile.
Best wishes,
Hans
Hans