Vous êtes sur la page 1sur 2

Macro for file importer

Sub TxtImporter()
Dim f As String, flPath As String
Dim i As Long, j As Long
Dim ws As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
flPath = ThisWorkbook.Path & Application.PathSeparator
i = ThisWorkbook.Worksheets.Count
j = Application.Workbooks.Count
f = Dir(flPath & "*.rpt")
Do Until f = ""
Workbooks.OpenText flPath & f, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=True, _
Space:=False, Other:=False, TrailingMinusNumbers:=True
Workbooks(j + 1).Worksheets(1).Copy After:=ThisWorkbook.Worksheets(i)
ThisWorkbook.Worksheets(i + 1).Name = Left(f, Len(f) - 4)
Workbooks(j + 1).Close SaveChanges:=False
i=i+1
f = Dir
Loop
Application.DisplayAlerts = True
End Sub

Add shet not working

Sub addsheets()

Dim wstest As Worksheet


Const strsheetname As String = "findme"

Set wstest = noting


On Error Resume Next
Set wstest = ActiveWorkbook.Worksheets(strsheetname)

If wstest Is Nothing Then


Worksheets.Add.Name = strsheetname
End If
End Sub
Add sheet not working for me

function addsheetifmissing(name As String) As Worksheet

On Error Resume Next


Set addsheetifmissing = ThisWorkbook.Worksheets(name)
If addsheesifmissing Is Nothing Then
Set addsheetmissing = ThisWorkbook.Worksheets.Add
addsheetifmissing.name = name
End If

End Function

Vous aimerez peut-être aussi