So basically I had to write the following in a Userform, then create a button named "ReadFile" and a field called "FileName".
Private Sub ReadFile_Click()
Dim tpOpenFname As ToFile
Dim lReturn As Long
Me.hide ' I hide the Userform but I can't really get a proper focus on the getOpenFile
With tpOpenFname
.lpstrFile = String(257, 0)
.nMaxFile = Len(tpOpenFname.lpstrFile)
.lStructSize = Len(tpOpenFname)
.lpstrFilter = "Text files (*.txt)" ' I want only to open txt
.nFilterIndex = 1
.lpstrFileTitle = tpOpenFname.lpstrFile
.nMaxFileTitle = tpOpenFname.nMaxFile
.lpstrInitialDir = "C:\"
.lpstrTitle = "Bitte eine Datei eingeben"
End With
lReturn = GetOpenFileName(tpOpenFname)
If lReturn = 0 Then
End
Else
Me.FileName = Left(tpOpenFname.lpstrFile, InStr(tpOpenFname.lpstrFile, ".txt") + 3)
'This is because I get silly symbols after the real filename (on "save" didn't have this problem though
End If
Me.Show
End Sub
And in the main module:
Read.Show vbModal ' to call the Userform
DatName = Read.FileName 'Read is the Userform name
Open DatName For Input As #1
As for "Save":
Private Sub SaveFile_Click()
Dim tpSaveFname As ToFile
Dim lReturn As Long
Me.hide
With tpSaveFname
.lpstrFile = String(257, 0)
.nMaxFile = Len(tpSaveFname.lpstrFile)
.lStructSize = Len(tpSaveFname)
.lpstrFilter = "Text files (*.txt)"
.nFilterIndex = 1
.lpstrFileTitle = tpSaveFname.lpstrFile
.nMaxFileTitle = tpSaveFname.nMaxFile
.lpstrInitialDir = "C:\"
.lpstrTitle = "Bitte eine Datei eingeben"
End With
lReturn = GetSaveFileName(tpSaveFname)
If lReturn = 0 Then
End
Else
Me.FileName = tpSaveFname.lpstrFile
Me.FileName = Me.FileName & ".txt"
End If
Me.Show
End Sub
And in the main module:
DatName = SaveAs.FileName 'SaveAs is the Userform name
Call Shell("C:\WINDOWS\notepad " & DatName, 1)