Sorry for the confusion, I did not put as much detail in as I sould have. Let me be more clear.Originally Posted by fumei
- I have a user form that pops up automatically when the word document (userform.doc) is opened.
- The user can click a button on the form called "readRIS" which opens the wdDialogFileOpen dialog. It shows the current directory where the userform.doc is located.
- The user can click on a file to select it. The file to open is a text file but has a .ris extension (e.g., myreferences.ris)
- NOTE: I use ".Display" instead of ".Show" to avoid executing the open command. I just want to get the file name so I can read the file in.
Code:
---------------------------
With Application.Dialogs(wdDialogFileOpen)
.Display
sFilename = .Name
End With
---------------------------
- I copy the contents of the textfile as a string to a textbox (called fText) on the form (already existing).
- I send the string containing the contents of "myreferences.ris" in the textbox to a parser which cleans up the data.
- The user can edit the text in the textbox (ftext).
Code
---------------------------
Public Sub ReadRIS_Click()
Dim sPath As String
With ActiveDocument
' Get filename
With Application.Dialogs(wdDialogFileOpen)
.Display
sFilename = .Name
End With
' Read .ris file
fText = ReadTextFile(sFilename)
' parse .ris file
fileStr = ParseRIS(fText)
' display .ris file and file name
fText = fileStr ' write parsed file to textbox
RISFileName = "source: " & sFilename ' show filename in textbox
End With
End Sub
---------------------------
- I now want the user to click save button (already existing) that saves the edited info in the textbox (ftext) to a different text file called myreferences.txt.
- Now there are two text files existing with the same name but different extensions. The first is the original myreferences.ris file and the second is the cleaned and edited version with a myreferences.txt extension.
It is working up to the point of saving the Textbox (ftext) to a new file called myreferences.txt. This is the part I am having trouble with.