I need a script to open a .txt file, insert pre-defined text into the start and end of the file, then close teh saved file with a .nc extension.
I'd like to have this so I can run it from my desktop.
I tried doing it in Word using macros and the FileDialog thingy to bring up dialogs for the user to select his files but it would not save the modified file for me and I couldn;t figure how to get it outside of Word. Code below.
Expand|Select|Wrap|Line Numbers
- ' Test1 Macro
- ' To open FIle-Open dialog box
- With Dialogs(wdDialogFileOpen)
- .Name = "*.txt"
- .Show
- End With
- ' To insert the text
- Selection.TypeParagraph
- Selection.TypeParagraph
- Selection.TypeParagraph
- Selection.HomeKey Unit:=wdStory
- Selection.TypeText Text:="The next line sends a 'Change State' command to system"
- Selection.TypeParagraph
- Selection.TypeText Text:="M3"
- Selection.TypeParagraph
- Selection.TypeText Text:="The next line tells system to Dwell for 5 seconds"
- Selection.TypeParagraph
- Selection.TypeText Text:="G04H5"
- 'This is where the error occurs
- With Dialogs(wdDialogFileSave)
- .Name = "*.*"
- .Show
- End With
- End Sub