Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
Merging Macro - GetOpenFilename & Workbooks.OpenText
thxs so much - working great!!
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
SOS-How to pass array parameter to Workbooks.OpenText(...) in VC++ | Excel Programming | |||
Workbooks.OpenText StartRow:=2 Not Skipping Row 1 | Excel Programming | |||
Workbooks.OpenText does not work on XP. HELP !!! | Excel Programming | |||
How to open UTF-8 files with Workbooks.OpenText | Excel Programming | |||
Workbooks.OpenText | Excel Programming |