Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Merging Macro - GetOpenFilename & Workbooks.OpenText

Sub GetImportFileName2()
Dim Filt As String
Dim FilterIndex As Integer
Dim FileName As Variant
Dim Title As String
Dim i As Integer
Dim Msg As String
' Set up list of file filters
Filt = "Text Files (*.txt),*.txt," & "Lotus Files (*.prn),*.prn," &
"Comma Separated Files (*.csv),*.csv," & "ASCII Files (*.asc),*.asc," &
"All Files (*.*),*.*"
' Display *.* by default
FilterIndex = 5
' Set the dialog box caption
Title = "Select a File to Import"""
' Get the file name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title, _
MultiSelect:=True)
' Exit if dialog box canceled
If Not IsArray(FileName) Then
MsgBox "No file was selected."""
Exit Sub
End If
' Display full path and name of the files
For i = LBound(FileName) To UBound(FileName)
Msg = Msg & FileName(i) & vbCrLf
Next i
MsgBox "You selected:" & vbCrLf & Msg


Workbooks.OpenText FileName:="C:\Directory\select.txt",
Origin:=xlWindows, _
StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0,
1), Array(31 _
, 4), Array(39, 1), Array(46, 1), Array(69, 1), Array(89, 1),
Array(109, 1), Array(111, 1))
Columns("A:J").Select
Columns("A:J").EntireColumn.AutoFit
Range("A1").Select


End Sub



Can anybody help me fixing the above macro

With what should I replace FileName:="C:\Directory\select.txt", to
make above macro work bearing in mind I can select more than 1 file

Thxs beforehand

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Merging Macro - GetOpenFilename & Workbooks.OpenText

Sub GetImportFileName2()
Dim Filt As String
Dim FilterIndex As Integer
Dim FileName As Variant
Dim Title As String
Dim i As Long
Dim Msg As String
' Set up list of file filters
Filt = "Text Files (*.txt),*.txt," & _
"Lotus Files (*.prn),*.prn," & _
"Comma Separated Files (*.csv),*.csv," & _
"ASCII Files (*.asc),*.asc," & _
"All Files (*.*),*.*"
' Display *.* by default
FilterIndex = 5
' Set the dialog box caption
Title = "Select Files to Import"""
' Get the file name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title, _
MultiSelect:=True)
' Exit if dialog box canceled
If Not IsArray(FileName) Then
MsgBox "No file was selected."""
Exit Sub
End If
' Display full path and name of the files
For i = LBound(FileName) To UBound(FileName)

Workbooks.OpenText FileName:=FileName(i), _
Origin:=xlWindows, _
StartRow:=1, _
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0,1), Array(31, 4), _
Array(39, 1), Array(46, 1), Array(69, 1), _
Array(89, 1), Array(109, 1), Array(111, 1))
Columns("A:J").Select
Columns("A:J").EntireColumn.AutoFit
Range("A1").Select
Next i
End Sub

--
Regards,
Tom Ogilvy



"al007" wrote in message
oups.com...
Sub GetImportFileName2()
Dim Filt As String
Dim FilterIndex As Integer
Dim FileName As Variant
Dim Title As String
Dim i As Integer
Dim Msg As String
' Set up list of file filters
Filt = "Text Files (*.txt),*.txt," & "Lotus Files (*.prn),*.prn," &
"Comma Separated Files (*.csv),*.csv," & "ASCII Files (*.asc),*.asc," &
"All Files (*.*),*.*"
' Display *.* by default
FilterIndex = 5
' Set the dialog box caption
Title = "Select a File to Import"""
' Get the file name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title, _
MultiSelect:=True)
' Exit if dialog box canceled
If Not IsArray(FileName) Then
MsgBox "No file was selected."""
Exit Sub
End If
' Display full path and name of the files
For i = LBound(FileName) To UBound(FileName)
Msg = Msg & FileName(i) & vbCrLf
Next i
MsgBox "You selected:" & vbCrLf & Msg


Workbooks.OpenText FileName:="C:\Directory\select.txt",
Origin:=xlWindows, _
StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0,
1), Array(31 _
, 4), Array(39, 1), Array(46, 1), Array(69, 1), Array(89, 1),
Array(109, 1), Array(111, 1))
Columns("A:J").Select
Columns("A:J").EntireColumn.AutoFit
Range("A1").Select


End Sub



Can anybody help me fixing the above macro

With what should I replace FileName:="C:\Directory\select.txt", to
make above macro work bearing in mind I can select more than 1 file

Thxs beforehand



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Merging Macro - GetOpenFilename & Workbooks.OpenText

thxs so much - working great!!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
SOS-How to pass array parameter to Workbooks.OpenText(...) in VC++ Lily Excel Programming 1 September 27th 05 02:05 PM
Workbooks.OpenText StartRow:=2 Not Skipping Row 1 John Saunders Excel Programming 2 August 26th 05 11:51 AM
Workbooks.OpenText does not work on XP. HELP !!! [email protected] Excel Programming 6 May 31st 05 03:18 PM
How to open UTF-8 files with Workbooks.OpenText Mete Kural Excel Programming 0 May 7th 05 01:25 AM
Workbooks.OpenText Alistair Eberst Excel Programming 2 October 21st 03 12:50 PM


All times are GMT +1. The time now is 02:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"