PC Review


Reply
Thread Tools Rate Thread

box to enter file name

 
 
Tonso
Guest
Posts: n/a
 
      5th Feb 2008
I am using Excel 2002 to import data from another program into a
spreadsheet, using the Text To columns feature. I have a macro that
works fine to go to the drive [K:/], and find the file, which is named
"mydata". is it possible to have a box appear that would enable a user
to name a different file, other than "mydata"? the macro starts off as
below.
As you can see, it is limited to the K dire3ctorry and the file name
"mydata". can i modify it to allow a differnt drive, and then allow a
different filename?
thank you


ChDir "K:\"
Workbooks.OpenText Filename:="K:\iedata.exp", Origin:=437,
StartRow:=1, _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
ConsecutiveDelimiter _
:=False, Tab:=True, Semicolon:=False, Comma:=False,
Space:=False, _
Other:=True, OtherChar:="|", FieldInfo:=Array(1, 1),
TrailingMinusNumbers _
:=True
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      5th Feb 2008
Option Explicit
Sub testme()

Dim myFileName As Variant

Dim CurFolder As String
Dim NewFolder As String
Dim TestStr As String

CurFolder = CurDir
NewFolder = "K:\"

'check to see if that newfolder actually exists
TestStr = ""
On Error Resume Next
TestStr = Dir(NewFolder & "\nul")
On Error GoTo 0

If TestStr = "" Then
MsgBox "design error!"
Else
ChDrive NewFolder
ChDir NewFolder
End If

myFileName = Application.GetOpenFilename(filefilter:="Excel Files, *.xls")

ChDrive CurFolder
ChDir CurFolder

If myFileName = False Then
Exit Sub
End If

Workbooks.OpenText Filename:=myfilename, Origin:=437, StartRow:=1, _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=True, OtherChar:="|", _
FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True

End Sub



Tonso wrote:
>
> I am using Excel 2002 to import data from another program into a
> spreadsheet, using the Text To columns feature. I have a macro that
> works fine to go to the drive [K:/], and find the file, which is named
> "mydata". is it possible to have a box appear that would enable a user
> to name a different file, other than "mydata"? the macro starts off as
> below.
> As you can see, it is limited to the K dire3ctorry and the file name
> "mydata". can i modify it to allow a differnt drive, and then allow a
> different filename?
> thank you
>
> ChDir "K:\"
> Workbooks.OpenText Filename:="K:\iedata.exp", Origin:=437,
> StartRow:=1, _
> DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
> ConsecutiveDelimiter _
> :=False, Tab:=True, Semicolon:=False, Comma:=False,
> Space:=False, _
> Other:=True, OtherChar:="|", FieldInfo:=Array(1, 1),
> TrailingMinusNumbers _
> :=True


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Feb 2008
Oops.

Change this line:
myFileName = Application.GetOpenFilename(filefilter:="Excel Files, *.xls")
to
myFileName = Application.GetOpenFilename(filefilter:="Exp Files, *.exp")

To limit it to *.exp files.

Dave Peterson wrote:
>
> Option Explicit
> Sub testme()
>
> Dim myFileName As Variant
>
> Dim CurFolder As String
> Dim NewFolder As String
> Dim TestStr As String
>
> CurFolder = CurDir
> NewFolder = "K:\"
>
> 'check to see if that newfolder actually exists
> TestStr = ""
> On Error Resume Next
> TestStr = Dir(NewFolder & "\nul")
> On Error GoTo 0
>
> If TestStr = "" Then
> MsgBox "design error!"
> Else
> ChDrive NewFolder
> ChDir NewFolder
> End If
>
> myFileName = Application.GetOpenFilename(filefilter:="Excel Files, *.xls")
>
> ChDrive CurFolder
> ChDir CurFolder
>
> If myFileName = False Then
> Exit Sub
> End If
>
> Workbooks.OpenText Filename:=myfilename, Origin:=437, StartRow:=1, _
> DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
> ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
> Comma:=False, Space:=False, Other:=True, OtherChar:="|", _
> FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
>
> End Sub
>
> Tonso wrote:
> >
> > I am using Excel 2002 to import data from another program into a
> > spreadsheet, using the Text To columns feature. I have a macro that
> > works fine to go to the drive [K:/], and find the file, which is named
> > "mydata". is it possible to have a box appear that would enable a user
> > to name a different file, other than "mydata"? the macro starts off as
> > below.
> > As you can see, it is limited to the K dire3ctorry and the file name
> > "mydata". can i modify it to allow a differnt drive, and then allow a
> > different filename?
> > thank you
> >
> > ChDir "K:\"
> > Workbooks.OpenText Filename:="K:\iedata.exp", Origin:=437,
> > StartRow:=1, _
> > DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
> > ConsecutiveDelimiter _
> > :=False, Tab:=True, Semicolon:=False, Comma:=False,
> > Space:=False, _
> > Other:=True, OtherChar:="|", FieldInfo:=Array(1, 1),
> > TrailingMinusNumbers _
> > :=True

>
> --
>
> Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
Tonso
Guest
Posts: n/a
 
      5th Feb 2008
On Feb 5, 3:12*pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> Option Explicit
> Sub testme()
>
> * * Dim myFileName As Variant
>
> * * Dim CurFolder As String
> * * Dim NewFolder As String
> * * Dim TestStr As String
>
> * * CurFolder = CurDir
> * * NewFolder = "K:\"
>
> * * 'check to see if that newfolder actually exists * *
> * * TestStr = ""
> * * On Error Resume Next
> * * TestStr = Dir(NewFolder & "\nul")
> * * On Error GoTo 0
>
> * * If TestStr = "" Then
> * * * * MsgBox "design error!"
> * * Else
> * * * * ChDrive NewFolder
> * * * * ChDir NewFolder
> * * End If
>
> * * myFileName = Application.GetOpenFilename(filefilter:="Excel Files, *.xls")
>
> * * ChDrive CurFolder
> * * ChDir CurFolder
>
> * * If myFileName = False Then
> * * * * Exit Sub
> * * End If
>
> * * Workbooks.OpenText Filename:=myfilename, Origin:=437, StartRow:=1, _
> * * * * DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
> * * * * ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
> * * * * Comma:=False, Space:=False, Other:=True, OtherChar:="|", _
> * * * * FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
>
> End Sub
>
>
>
>
>
> Tonso wrote:
>
> > I am using Excel 2002 to import data from another program into a
> > spreadsheet, using the Text To columns feature. I have a macro that
> > works fine to go to the drive [K:/], and find the file, which is named
> > "mydata". is it possible to have a box appear that would enable a user
> > to name a different file, other than "mydata"? the macro starts off as
> > below.
> > As you can see, it is limited to the K dire3ctorry and the file name
> > "mydata". can i modify it to allow a differnt drive, and then allow a
> > different filename?
> > thank you

>
> > ChDir "K:\"
> > * * Workbooks.OpenText Filename:="K:\iedata.exp", Origin:=437,
> > StartRow:=1, _
> > * * * * DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
> > ConsecutiveDelimiter _
> > * * * * :=False, Tab:=True, Semicolon:=False, Comma:=False,
> > Space:=False, _
> > * * * * Other:=True, OtherChar:="|", FieldInfo:=Array(1, 1),
> > TrailingMinusNumbers _
> > * * * * :=True

>
> --
>
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


Works like a charm! Thanks you so very much!
Siege
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enter file path in text box, use button to open file silva Microsoft Access 2 29th May 2008 07:15 PM
I cannot enter the file in the server skymen Windows Vista Networking 1 15th Apr 2008 04:43 AM
How do I open a file with enter when I enter a file with a unique =?Utf-8?B?V29yZFdvcmtlcg==?= Microsoft Word Document Management 1 21st Jul 2006 02:27 PM
Enter user name, enter password, then press enter... =?Utf-8?B?UGF1bCAoRVNJKQ==?= Microsoft Access Forms 6 11th Jul 2005 05:41 PM
how to add <Enter> on a new line in a .bat file JW Microsoft Windows 2000 CMD Promt 4 8th Jun 2004 05:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:43 AM.