-
Notifications
You must be signed in to change notification settings - Fork 0
/
carregarArquivoOs.bas
77 lines (46 loc) · 2.35 KB
/
carregarArquivoOs.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Attribute VB_Name = "carregarArquivoOs"
' ESTE PROCEDIMENTO ABRE O ARQUIVO CSV ESCOLHIDO E COLA NA PLANILHA PASSADA COMO PARAMETRO
Public Const ERRO_DE_CABECALHO As Long = vbObjectError + 513
Sub carregar_Os(ByVal planilha As String)
On Error GoTo TE
Dim arquivoEscolhido As String
arquivoEscolhido = Application.GetOpenFilename("CSV File (*.csv), *.csv", , "Escolha um arquivo CSV de relat�rio de OS's", , False)
Worksheets(planilha).Cells.Clear
If Not (arquivoEscolhido = "Falso") Then
With Worksheets(planilha).QueryTables.Add("TEXT;" + arquivoEscolhido, Worksheets(planilha).Range("A1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Dim cabecalho As Variant
cabecalho = Join(Application.Transpose(Application.Transpose(Worksheets("Configura��es").Range("G4:AL4"))), "")
If Join(Application.Transpose(Application.Transpose(Worksheets("Os").UsedRange.Rows(1))), "") <> cabecalho Then
Worksheets("Os").Cells.Clear
userFormPrincipal.textboxOs.Text = ""
Err.Raise ERRO_DE_CABECALHO, "Erro de cabe�alho" _
, "Arquivo csv com cabe�alho inv�lido."
End If
userFormPrincipal.textboxOs.Text = arquivoEscolhido
End If
Exit Sub
TE: 'Tratamento de Erros
MsgBox " Erro: " & Err.Description & Chr(13) & Chr(13) & "Local: M�dulo carregarArquivoOs.carregar_Os"
End Sub