Rename Thousands of Recipe *.txt files
[QUOTE=fumei;219234]First off...
Quote:
Then the code should go through IF statement with the following rules.
If keyword=”chief complaint”, make variable “T_Document”= chart_note
IF keyword=”billing statemen”t, make variable “T_Document”=billing statement
IF keyword=“Mark Gventer, D.P.M., F.A.C.F.O.”, make variable “T_Document”=prescription
If keyword=”DAILY SIGNATURE FORM”, make variable “T_Document”=daily signature
If keyword=“PRIVACY PRACTICES ACKNOWLEDGEMENT”, make variable “T_Document”=privacy
[/quote}No! Do not use an bu7nch of IF statements. This is precisely wehat Select Case is used for. Here is why.
ALL your IF statements will be executed, because they are independent instructions - there is NO inherent logic linking then (at least to VBA). Here is the same result using Select Case:[vba]
' Then the code should go through with the following rules.
Select Case keyword
Case ”chief complaint”
T_Document = "chart_note"
Case ”billing statement"
T_Document = "billing statement"
Case “Mark Gventer, D.P.M., F.A.C.F.O.”
T_Document = "prescription"
Case ”DAILY SIGNATURE FORM”
T_Document = "daily signature"
Case "PRIVACY PRACTICES ACKNOWLEDGEMENT”
T_Document = "privacy"
End Select
[/vba]Select Case testing multiple values for the same variable - in this case, the variable keyword (I am not happy with that name though, as it seems close to being a restricted term)
As for: "Then I need to go through the text that is pasted by function Selection.Paste (please see the code above) "
I do not follow. There is a Sub above (not a Function). And I am unclear as to what it is doing. Using Selection is not a good idea.
BTW: I do not know if your posted file has macros, as I do not use 2007, and convertin git strips all code.
Moderator Edit: This refers to :http://www.vbaexpress.com/forum/showthread.php?32476
I solved this with 3 days of serious reading.
I was able to come up with a solution for renaming text files based on the first line of the file itself. To begin, I have thousands of original recipes that I have created over the years. My goal is to have them all as text files so I can create a database. Many are Word .doc, .docx or .xlx and are named as 1_.doc, 2_doc, 3_doc, 005_.xls etc…
To convert these to .txt I used a program called Doxcillion---that was easy as it converted a few thousand .doc files in a minute or two. Only later I found that the conversion was to UTF-8-BOM and that after running my rename.bat file, weird special characters were added before each file name. The files needed to be encoded as UTF-8 or UTF-16 before running the rename file on them. (It seems to be an issue that others have experienced from the posts I read online). So now I downloaded a free program, for personal use, called UTFCast Express. It changed the encoding of all my .txt files to UTF-8 in an instant.
I ran rename .bat---(I'd like to post the .bat code but the forum is blocking me from doing so. How can I show it to you?)
Continued from above--------------------------------------
Most files were renamed as what the very first line of text was in the file, i.e. Bacon and Onion Muffins.txt, Chocolate Mousse.txt, Rumaki.txt and on and on. However, some of my recipes were written where the title was not on the first line but the second or third and they were not renamed, they stayed the same. Ugh, I had to go back and delete all the blank lines above the titles to move every title to the very first line. I used Notepad++ and Texpipe Lite with Easy Pattern Helper to do that. Once this was corrected and there was no white space in front of the tile, rename.bat ran like a charm!
My files are now named from the first line of the .txt file although the file names are exactly as written in the text file, with capital letters and spaces like these---Boneless Center Cut Pork Loin Florentine .txt or Peach Cobbler with Cheddar Biscuits.txt (notice the spaces between words and in front of .txt) on the pork file---and that's how it and others are written in the recipe " Boneless Center Cut Pork Loin Florentine(with a single space after it. The biscuit title didn't have a single space after it, so there is no space before .txt).