A save/load txt UserForm

  • Thread starter Thread starter Abe
  • Start date Start date
A

Abe

I have used Walkenbach's method of saving/loading to text files in his
Power Programming with VBA (2003), but would like to have an
accompanying UserForm that allows the user to search through
directories to both load and save their files--much like the way the
save/load works for any Office product. Anybody have a copy of such
code lying around? Or know a good place to look?
 
abe, use Excel's FileDialogOpen or many other similar file utilities.

simplest one being...
Application.GetOpenFilename

my personal favorite is a home brew...

Option Explicit
Public Type FileProperties
SFile As String
SvLoc As String
Cancelled As Boolean
End Type

Function OpenSesame(ClFilters As Boolean, OTitle As String, _
MultiSelect As Boolean, Optional Fltr As String, Optional FltrName
As String, _
Optional StartFolder As String) As FileProperties

OpenSesame.SFile = Empty
OpenSesame.SvLoc = Empty
OpenSesame.Cancelled = False

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = MultiSelect
If Not IsEmpty(OTitle) Then .Title = OTitle
If Not IsEmpty(StartFolder) Then .InitialFileName = StartFolder
If ClFilters = True Then .Filters.Clear
If Not Fltr = "" Then
If Not FltrName = "" Then
.Filters.Add FltrName, Fltr
Else
.Filters.Add "User Filter", Fltr
End If
.FilterIndex = .Filters.Count
End If
If .Show = True Then
OpenSesame.SFile = .SelectedItems(1)
OpenSesame.SvLoc = .InitialFileName
Else
OpenSesame.Cancelled = True
End If
End With

End Function

HTH

Die_Another_Day
 
Thanks.

Looks like it'll work great.
-Abe
Die_Another_Day said:
abe, use Excel's FileDialogOpen or many other similar file utilities.

simplest one being...
Application.GetOpenFilename

my personal favorite is a home brew...

Option Explicit
Public Type FileProperties
SFile As String
SvLoc As String
Cancelled As Boolean
End Type

Function OpenSesame(ClFilters As Boolean, OTitle As String, _
MultiSelect As Boolean, Optional Fltr As String, Optional FltrName
As String, _
Optional StartFolder As String) As FileProperties

OpenSesame.SFile = Empty
OpenSesame.SvLoc = Empty
OpenSesame.Cancelled = False

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = MultiSelect
If Not IsEmpty(OTitle) Then .Title = OTitle
If Not IsEmpty(StartFolder) Then .InitialFileName = StartFolder
If ClFilters = True Then .Filters.Clear
If Not Fltr = "" Then
If Not FltrName = "" Then
.Filters.Add FltrName, Fltr
Else
.Filters.Add "User Filter", Fltr
End If
.FilterIndex = .Filters.Count
End If
If .Show = True Then
OpenSesame.SFile = .SelectedItems(1)
OpenSesame.SvLoc = .InitialFileName
Else
OpenSesame.Cancelled = True
End If
End With

End Function

HTH

Die_Another_Day
 
Look at GetOpenFilename in VBA Help.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top