Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Run "RemoveFromMenu"
End Sub
Private Sub Workbook_Open()
Run "RemoveFromMenu"
With Application.CommandBars("Cell")
.Controls.Add(Type:=msoControlButton). _
Caption = "Import text (column)"
.Controls.Add(Type:=msoControlButton). _
Caption = "Import text (selection)"
.Controls("Import text (column)"). _
OnAction = "Import2NextCol"
.Controls("Import text (selection)"). _
OnAction = "Import2ActiveCell"
End With
End Sub
Option Explicit
Sub Import2ActiveCell()
Dim Filt$, Title$, FileText$, FileName$, N&
If Selection.Cells.Count > 1 Then
MsgBox "Please select one cell only", , "Starting-Point is Unclear..."
Exit Sub
End If
Filt = "VB Files (*.bas; *.frm; *.cls;*.txt;*.log;*.frx) " & _
"(*.bas; *.frm; *.cls;*.txt;*.log;*.frx)," & _
"*.bas;*.frm;*.cls;*.txt;*.log;*.frx"
Title = "SELECT A FOLDER - DOUBLE-CLICK OR CLICK " & _
"OPEN TO IMPORT - CANCEL TO QUIT"
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, FilterIndex:=5, Title:=Title)
If Dir(FileName) <> Empty Then
Application.ScreenUpdating = False
Open (FileName) For Input As #1
N = ActiveCell.Row
Do While Not EOF(1)
Input #1, FileText
Cells(N, ActiveCell.Column) = FileText
N = N + 1
Loop
Close #1
ActiveWindow.DisplayGridlines = False
With Cells
.Font.Size = 9
Columns.AutoFit
Rows.AutoFit
End With
ActiveCell.Select
End If
End Sub
Sub Import2NextCol()
Dim Filt$, Title$, FileText$
Dim FileName$, N&, FirstEmpty&
Filt = "VB Files (*.bas; *.frm; *.cls;*.txt;*.log;*.frx) " & _
"(*.bas; *.frm; *.cls;*.txt;*.log;*.frx)," & _
"*.bas;*.frm;*.cls;*.txt;*.log;*.frx"
Title = "SELECT A FOLDER - DOUBLE-CLICK OR CLICK " & _
"OPEN TO IMPORT - CANCEL TO QUIT"
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, FilterIndex:=5, Title:=Title)
On Error GoTo IsBlankSheet
FirstEmpty = Cells.Find("*", SearchOrder:=xlByColumns, _
LookIn:=xlValues, SearchDirection:=xlPrevious). _
Column + 1
If FirstEmpty = 257 Then
MsgBox "Sorry, no more columns on this sheet"
Exit Sub
End If
TextEntry:
If Dir(FileName) <> Empty Then
Application.ScreenUpdating = False
Open (FileName) For Input As #1
N = 1
Do While Not EOF(1)
Input #1, FileText
Rows(N).Columns(FirstEmpty) = FileText
N = N + 1
Loop
Close #1
ActiveWindow.DisplayGridlines = False
With Cells
.Font.Size = 9
Columns.AutoFit
Rows.AutoFit
End With
Application.Goto Rows(1).Columns(FirstEmpty), scroll:=True
End If
Exit Sub
IsBlankSheet:
FirstEmpty = 1
Resume TextEntry
End Sub
Private Sub RemoveFromMenu()
On Error Resume Next
With Application.CommandBars("Cell")
.Controls("Import text (column)").Delete
.Controls("Import text (selection)").Delete
End With
End Sub
|