Estou usando este coodigo para importar um arquivo txt , só que se abrir o "mini" explorer de arquivos e clicar em cancelar dá:
ERRO EM TEMPO DE EXECUÇÃO '53': O arquivo não foi localizado.
Como eliminar esse erro?
If Range("AQ97") = 1 Then
'Contador de linhas
i = 1
'abre um "mini" explorer de arquivos
ArquivoTxt = Application.GetOpenFilename("Arquivos Texto(*.txt), *.txt")
'abre o arquivo texto
Open ArquivoTxt For Input As #1
ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & ArquivoTxt, Destination:=Range("bl97")).Refresh BackgroundQuery:=False
'fecha o arquivo texto
Close #1
'Cells.EntireColumn.AutoFit ' autoajuste da largura da coluna
Range("bl97:IV99").Select
Selection.Delete shift:=xlUp
Range("bl98:IV98").Select
Selection.Delete shift:=xlUp
Columns("bm:bm").Select
Selection.Copy
Columns("bj:bj").Select
Range("bj97").Activate
ActiveSheet.Paste
Columns("bp:bp").Select
Application.CutCopyMode = False
Selection.Copy
Columns("bk:bk").Select
Range("bk97").Activate
ActiveSheet.Paste
Columns("bl:IV").Select
Range("bl97").Activate
Application.CutCopyMode = False
Selection.QueryTable.Delete
Selection.ClearContents
Range("bj:Bk").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Font.Bold = False
With Selection.Font
.Name = "Arial"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("Bg97:Bh97").Select
Selection.Font.Bold = True
With Selection.Font
.Name = "Arial"
.Size = 16
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("AQ97").Value = 0
Rows("97:97").Select
Selection.RowHeight = 73.5
Rows("100:123").Select
Selection.RowHeight = 45.5
Range("D100").Select
Columns("BJ:BK").Select
Selection.Replace What:=" 7", Replacement:=" ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="23 K ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ProtCell
Prot2
MsgBox "Importação Concluida Com Sucesso", vbMsgBoxSetForeground
Else
MsgBox "VOCÊ JÁ EFETUOU A IMPORTAÇÃO DO ARQUIVO", vbMsgBoxSetForeground
End If
ProtCell
Prot2
End Sub
Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel
Postado : 30/04/2012 11:53 am