ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   A save/load txt UserForm (https://www.excelbanter.com/excel-programming/368593-save-load-txt-userform.html)

Abe[_4_]

A save/load txt UserForm
 
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?


Die_Another_Day

A save/load txt UserForm
 
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
Abe wrote:
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[_4_]

A save/load txt UserForm
 
Thanks.

Looks like it'll work great.
-Abe
Die_Another_Day wrote:
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
Abe wrote:
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?



Bob Phillips

A save/load txt UserForm
 
Look at GetOpenFilename in VBA Help.

--
HTH

Bob Phillips

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

"Abe" wrote in message
oups.com...
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?





All times are GMT +1. The time now is 03:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com