![]() ![]() It is like Word recognized the XML like structure and just got rid of it. For some reason it stripped out all of the bracketed information and left just the values of the parameters. There is a problem with the formatting, however. It would have taken me a month of Sundays to get that code written, and I probably would not have been anywhere near that efficient. If that bothers you, it can be suppressed, but I see it as a sign that the macro is still running. This opening and closing causes the status bar to flicker. Each time the XML file is opened, modified, and saved to another name, the macro closes it and then reopens the unmodified file to prepare for the next iteration.To avoid that, this macro first loops through all the occurrences of 'XYZ' and changes them to 'xyz' then the later replacement preserves the case of the data. That's a shortcoming of the Range.Find object. If the XML file contains 'XYZ' in all caps, and the macro tried to replace that with lower-case or mixed-case text from the data file, the result would be all caps.The XML file and the output files can be in any folder, and not necessarily in the same folder with each other.There are a couple of interesting wrinkles in this code. Open the document and double-click the macrobutton field to start it up. MsgBox "Error " & Err.Number & " at line " & iterNum & vbCr & Err.Description Set baseFile = Documents.Open(FileName:=baseFileFN, AddToRecentFiles:=False, Visible:=False) ' close the modified file, then reopen the unmodified baseīaseFile.Close SaveChanges:=wdDoNotSaveChanges ' to avoid inserting text from data file in all capsįileName:=saveFN & Format(iterNum, "0000") & ".prtl", _ ReplaceText = Left(, Len() - 1) ' exclude paragraph mark RgData.MoveStart unit:=wdParagraph, Count:=1 ' exclude paragraph containing macro button SaveFN = WordBasic.FileNameInfo(.Name, 5) & WordBasic.FileNameInfo(.Name, 4) & "-" ![]() Display = -1 Then ' just get the path\name, don't actually save MsgBox "Select the folder and filename (without numbers) to save as." Set baseFile = ActiveDocument ' file just opened becomes ActiveīaseFileFN = baseFile.FullName ' this path\name will be used to open it again MsgBox "Select the data file (*.prtl) to be processed." We have the pedestal all ready for you to stand on.ĭim dataFile As Document ' this data doc or templateĭim baseFile As Document ' file being modifiedĭim baseFileFN As String ' path\name of file from Adobeĭim rgData As Range ' range of data file containing replacementsĭim para As Paragraph ' paragraph in rgDataĭim rgPattern As Range ' a range used in baseFileĭim replaceText As String ' current line from this data fileĭim iterNum As Long ' number of current line / saved fileĭim saveFN As String ' path\base name of saved file If you would be willing to code it and want credit for your work, the entire Adobe video editing community would be happy to shower you with praise. Thank you for taking the time to read this and if you can help, I would be appreciative. It seems like it should be easy but the actual code is escaping me. In case it helps, the section of the file I am changing looks like this: This should leave me with a directory full of individual files numbered sequentially. Save As filename plus -n ''''Save text file to new name - n is a number that increments from 0001 to 9999 Read first line of data file ''''usually not more than 40 characters but could be up to 255 Search for XYZ ''''XYZ being the temporary text I use to help identify the place in the file that needs to be changed This is the file where the Macro button resides.įile Open Dialog ''''find and open the text file that I will change over and over again I open the Data file which has multiple lines of text - anywhere from 2 to 1000 or more. It seems to me that it should look something like this: So it could be and I could find and replace it to achieve my goal. If I export a title I get a text file (XML) filled with all kinds of stuff, but the text I want to change is just plain text. I am using 2003, 20 versions of Word, and I imagine the people I will be sharing this with will be as well. I am hoping the code is pretty generic and will not have changed much, if at all. I would prefer having it work across multiple versions of Word if possible. If you could code it, I would be ever so grateful. If you could just supply the right words for the concepts in the pseudocode, that would be great. I used to hang out on forums like this answering questions like this about Visual Basic back when Windows 3.1 was the OS. I have not needed to code anything in over 20 years. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |