Sub GeradorBancoDeDados()
Dim FiletoOpen As String
Dim wbd As Workbook 'workbook da base de dados (where info needs to go)
Dim wsd As Worksheet 'worksheet da base de dados
Dim wbt As Workbook 'workbook temporario para extração de informação (where info comes from)
Dim wst As Worksheet 'worksheet temporario para extração da informação
Dim i As Integer
'these are just variables (the simplest way I thought of taking the info from the workbook)
Dim nomecliente As String
Dim cpfcliente As String
Dim datacliente As String
Dim endcliente As String
Dim bairrocliente As String
Dim cepcliente As String
Dim cidadufcliente As String
Dim telecliente As String
Dim emailcliente As String
Dim obscliente As String
Dim endentrega As String
Dim bairroentrega As String
Dim cepentrega As String
Dim cidadufentrega As String
Dim telentrega As String
Dim emailentrega As String
Dim obsentrega As String
Dim obsgercliente As String
Dim boletoemailcliente As String
Dim boletoimpcliente As String
Dim lacradocliente As String
Dim numpedido As String
Dim RSpj As String
Dim Datapj As String
Dim NFpj As String
Dim CNPJpj As String
Dim Contatopj As String
Dim InsSocpj As String
Dim Endpj As String
Dim bairropj As String
Dim ceppj As String
Dim cidufpj As String
Dim telspj As String
Dim emailpj As String
Dim obspj As String
Dim Endentregapj As String
Dim bairroentregapj As String
Dim cepentregapj As String
Dim cidufentregapj As String
Dim telentregapj As String
Dim emailentregapj As String
Dim obsentregapj As String
Dim obsgeralentregapj As String
Dim boletemailpj As String
Dim boletoimpressopj As String
Dim enveloplacradopj As String
Dim numpedidopj As String
Sheets("Files").Select
Range("C9").Select
Set wbd = ThisWorkbook
Set wsd = ActiveSheet
Do While ActiveCell <> Empty
FiletoOpen = "C:\Users\Luis\Desktop\Carols\Pedidos\" & ActiveCell.Value
Application.Workbooks.Open (FiletoOpen) 'Abrir workbook cliente
Set wbt = ActiveWorkbook
Application.ScreenUpdating = False
For i = 1 To wbt.Worksheets.Count
Sheets(i).Unprotect Password:="AABBAAAAABBT"
Sheets(i).Select
Cells.Select
Selection.UnMerge
Next
'extração da informção do sheet Pessoa Fisica (Extract info from sheet 1)
i = 1
nomecliente = Trim(Mid(wbt.Sheets(i).Range("A1"), InStr(wbt.Sheets(i).Range("A1"), ":") + 1, Len(wbt.Sheets(i).Range("A1")) - InStr(wbt.Sheets(i).Range("A1"), ":") + 1))
cpfcliente = Trim(Mid(wbt.Sheets(i).Range("D1"), InStr(wbt.Sheets(i).Range("D1"), ":") + 1, Len(wbt.Sheets(i).Range("D1")) - InStr(wbt.Sheets(i).Range("D1"), ":") + 1))
datacliente = Trim(Mid(wbt.Sheets(i).Range("F1"), InStr(wbt.Sheets(i).Range("F1"), ":") + 1, Len(wbt.Sheets(i).Range("F1")) - InStr(wbt.Sheets(i).Range("F1"), ":") + 1))
endcliente = Trim(Mid(wbt.Sheets(i).Range("A2"), InStr(wbt.Sheets(i).Range("A2"), ":") + 1, Len(wbt.Sheets(i).Range("A2")) - InStr(wbt.Sheets(i).Range("A2"), ":") + 1))
bairrocliente = Trim(Mid(wbt.Sheets(i).Range("A3"), InStr(wbt.Sheets(i).Range("A3"), ":") + 1, Len(wbt.Sheets(i).Range("A3")) - InStr(wbt.Sheets(i).Range("A3"), ":") + 1))
cepcliente = Trim(Mid(wbt.Sheets(i).Range("D3"), InStr(wbt.Sheets(i).Range("D3"), ":") + 1, Len(wbt.Sheets(i).Range("D3")) - InStr(wbt.Sheets(i).Range("D3"), ":") + 1))
cidadufcliente = Trim(Mid(wbt.Sheets(i).Range("F3"), InStr(wbt.Sheets(i).Range("F3"), ":") + 1, Len(wbt.Sheets(i).Range("F3")) - InStr(wbt.Sheets(i).Range("F3"), ":") + 1))
telecliente = Trim(Mid(wbt.Sheets(i).Range("A4"), InStr(wbt.Sheets(i).Range("A4"), ":") + 1, Len(wbt.Sheets(i).Range("A4")) - InStr(wbt.Sheets(i).Range("A4"), ":") + 1))
emailcliente = Trim(Mid(wbt.Sheets(i).Range("D4"), InStr(wbt.Sheets(i).Range("D4"), ":") + 1, Len(wbt.Sheets(i).Range("D4")) - InStr(wbt.Sheets(i).Range("D4"), ":") + 1))
obscliente = Trim(Mid(wbt.Sheets(i).Range("A5"), InStr(wbt.Sheets(i).Range("A5"), ":") + 1, Len(wbt.Sheets(i).Range("A5")) - InStr(wbt.Sheets(i).Range("A5"), ":") + 1))
endentrega = Trim(Mid(wbt.Sheets(i).Range("A7"), InStr(wbt.Sheets(i).Range("A7"), ":") + 1, Len(wbt.Sheets(i).Range("A7")) - InStr(wbt.Sheets(i).Range("A7"), ":") + 1))
bairroentrega = Trim(Mid(wbt.Sheets(i).Range("A8"), InStr(wbt.Sheets(i).Range("A8"), ":") + 1, Len(wbt.Sheets(i).Range("A8")) - InStr(wbt.Sheets(i).Range("A8"), ":") + 1))
cepentrega = Trim(Mid(wbt.Sheets(i).Range("D8"), InStr(wbt.Sheets(i).Range("D8"), ":") + 1, Len(wbt.Sheets(i).Range("D8")) - InStr(wbt.Sheets(i).Range("D8"), ":") + 1))
cidadufentrega = Trim(Mid(wbt.Sheets(i).Range("F8"), InStr(wbt.Sheets(i).Range("F8"), ":") + 1, Len(wbt.Sheets(i).Range("F8")) - InStr(wbt.Sheets(i).Range("F8"), ":") + 1))
telentrega = Trim(Mid(wbt.Sheets(i).Range("A9"), InStr(wbt.Sheets(i).Range("A9"), ":") + 1, Len(wbt.Sheets(i).Range("A9")) - InStr(wbt.Sheets(i).Range("A9"), ":") + 1))
emailentrega = Trim(Mid(wbt.Sheets(i).Range("D9"), InStr(wbt.Sheets(i).Range("D9"), ":") + 1, Len(wbt.Sheets(i).Range("D9")) - InStr(wbt.Sheets(i).Range("D9"), ":") + 1))
obsentrega = Trim(Mid(wbt.Sheets(i).Range("A10"), InStr(wbt.Sheets(i).Range("A10"), ":") + 1, Len(wbt.Sheets(i).Range("A10")) - InStr(wbt.Sheets(i).Range("A10"), ":") + 1))
obsgercliente = Trim(Mid(wbt.Sheets(i).Range("A12"), InStr(wbt.Sheets(i).Range("A12"), ":") + 1, Len(wbt.Sheets(i).Range("A12")) - InStr(wbt.Sheets(i).Range("A12"), ":") + 1))
boletoemailcliente = Trim(Mid(wbt.Sheets(i).Range("A15"), InStr(wbt.Sheets(i).Range("A15"), ":") + 1, Len(wbt.Sheets(i).Range("A15")) - InStr(wbt.Sheets(i).Range("A15"), ":") + 1))
boletoimpcliente = Trim(Mid(wbt.Sheets(i).Range("A16"), InStr(wbt.Sheets(i).Range("A16"), ":") + 1, Len(wbt.Sheets(i).Range("A16")) - InStr(wbt.Sheets(i).Range("A16"), ":") + 1))
lacradocliente = Trim(Mid(wbt.Sheets(i).Range("D16"), InStr(wbt.Sheets(i).Range("D16"), ":") + 1, Len(wbt.Sheets(i).Range("D16")) - InStr(wbt.Sheets(i).Range("D16"), ":") + 1))
'extração da informação do sheet Pessoa Juridica (extract info from sheet 2)
i = 2
RSpj = Trim(Mid(wbt.Sheets(i).Range("A1"), InStr(wbt.Sheets(i).Range("A1"), ":") + 1, Len(wbt.Sheets(i).Range("A1")) - InStr(wbt.Sheets(i).Range("A1"), ":") + 1))
Datapj = Trim(Mid(wbt.Sheets(i).Range("F1"), InStr(wbt.Sheets(i).Range("F1"), ":") + 1, Len(wbt.Sheets(i).Range("F1")) - InStr(wbt.Sheets(i).Range("F1"), ":") + 1))
NFpj = Trim(Mid(wbt.Sheets(i).Range("A2"), InStr(wbt.Sheets(i).Range("A2"), ":") + 1, Len(wbt.Sheets(i).Range("A2")) - InStr(wbt.Sheets(i).Range("A2"), ":") + 1))
CNPJpj = Trim(Mid(wbt.Sheets(i).Range("F2"), InStr(wbt.Sheets(i).Range("F2"), ":") + 1, Len(wbt.Sheets(i).Range("F2")) - InStr(wbt.Sheets(i).Range("F2"), ":") + 1))
Contatopj = Trim(Mid(wbt.Sheets(i).Range("A3"), InStr(wbt.Sheets(i).Range("A3"), ":") + 1, Len(wbt.Sheets(i).Range("A3")) - InStr(wbt.Sheets(i).Range("A3"), ":") + 1))
InsSocpj = Trim(Mid(wbt.Sheets(i).Range("F3"), InStr(wbt.Sheets(i).Range("F3"), ":") + 1, Len(wbt.Sheets(i).Range("F3")) - InStr(wbt.Sheets(i).Range("F3"), ":") + 1))
Endpj = Trim(Mid(wbt.Sheets(i).Range("A4"), InStr(wbt.Sheets(i).Range("A4"), ":") + 1, Len(wbt.Sheets(i).Range("A4")) - InStr(wbt.Sheets(i).Range("A4"), ":") + 1))
bairropj = Trim(Mid(wbt.Sheets(i).Range("A5"), InStr(wbt.Sheets(i).Range("A5"), ":") + 1, Len(wbt.Sheets(i).Range("A5")) - InStr(wbt.Sheets(i).Range("A5"), ":") + 1))
ceppj = Trim(Mid(wbt.Sheets(i).Range("D5"), InStr(wbt.Sheets(i).Range("D5"), ":") + 1, Len(wbt.Sheets(i).Range("D5")) - InStr(wbt.Sheets(i).Range("D5"), ":") + 1))
cidufpj = Trim(Mid(wbt.Sheets(i).Range("F5"), InStr(wbt.Sheets(i).Range("F5"), ":") + 1, Len(wbt.Sheets(i).Range("F5")) - InStr(wbt.Sheets(i).Range("F5"), ":") + 1))
telspj = Trim(Mid(wbt.Sheets(i).Range("A6"), InStr(wbt.Sheets(i).Range("A6"), ":") + 1, Len(wbt.Sheets(i).Range("A6")) - InStr(wbt.Sheets(i).Range("A6"), ":") + 1))
emailpj = Trim(Mid(wbt.Sheets(i).Range("D6"), InStr(wbt.Sheets(i).Range("D6"), ":") + 1, Len(wbt.Sheets(i).Range("D6")) - InStr(wbt.Sheets(i).Range("D6"), ":") + 1))
obspj = Trim(Mid(wbt.Sheets(i).Range("A7"), InStr(wbt.Sheets(i).Range("A7"), ":") + 1, Len(wbt.Sheets(i).Range("A7")) - InStr(wbt.Sheets(i).Range("A7"), ":") + 1))
Endentregapj = Trim(Mid(wbt.Sheets(i).Range("A9"), InStr(wbt.Sheets(i).Range("A9"), ":") + 1, Len(wbt.Sheets(i).Range("A9")) - InStr(wbt.Sheets(i).Range("A9"), ":") + 1))
bairroentregapj = Trim(Mid(wbt.Sheets(i).Range("A10"), InStr(wbt.Sheets(i).Range("A10"), ":") + 1, Len(wbt.Sheets(i).Range("A1")) - InStr(wbt.Sheets(i).Range("A10"), ":") + 1))
cepentregapj = Trim(Mid(wbt.Sheets(i).Range("D10"), InStr(wbt.Sheets(i).Range("D10"), ":") + 1, Len(wbt.Sheets(i).Range("D10")) - InStr(wbt.Sheets(i).Range("D10"), ":") + 1))
cidufentregapj = Trim(Mid(wbt.Sheets(i).Range("F10"), InStr(wbt.Sheets(i).Range("F10"), ":") + 1, Len(wbt.Sheets(i).Range("F10")) - InStr(wbt.Sheets(i).Range("F10"), ":") + 1))
telentregapj = Trim(Mid(wbt.Sheets(i).Range("A11"), InStr(wbt.Sheets(i).Range("A11"), ":") + 1, Len(wbt.Sheets(i).Range("A11")) - InStr(wbt.Sheets(i).Range("A11"), ":") + 1))
emailentregapj = Trim(Mid(wbt.Sheets(i).Range("D11"), InStr(wbt.Sheets(i).Range("D11"), ":") + 1, Len(wbt.Sheets(i).Range("D11")) - InStr(wbt.Sheets(i).Range("D11"), ":") + 1))
obsentregapj = Trim(Mid(wbt.Sheets(i).Range("A12"), InStr(wbt.Sheets(i).Range("A12"), ":") + 1, Len(wbt.Sheets(i).Range("A12")) - InStr(wbt.Sheets(i).Range("A12"), ":") + 1))
obsgeralentregapj = Trim(Mid(wbt.Sheets(i).Range("A14"), InStr(wbt.Sheets(i).Range("A14"), ":") + 1, Len(wbt.Sheets(i).Range("A14")) - InStr(wbt.Sheets(i).Range("A14"), ":") + 1))
boletemailpj = Trim(Mid(wbt.Sheets(i).Range("A17"), InStr(wbt.Sheets(i).Range("A17"), ":") + 1, Len(wbt.Sheets(i).Range("A17")) - InStr(wbt.Sheets(i).Range("A17"), ":") + 1))
boletoimpressopj = Trim(Mid(wbt.Sheets(i).Range("A18"), InStr(wbt.Sheets(i).Range("A18"), ":") + 1, Len(wbt.Sheets(i).Range("A18")) - InStr(wbt.Sheets(i).Range("A18"), ":") + 1))
enveloplacradopj = Trim(Mid(wbt.Sheets(i).Range("D18"), InStr(wbt.Sheets(i).Range("D18"), ":") + 1, Len(wbt.Sheets(i).Range("D18")) - InStr(wbt.Sheets(i).Range("D18"), ":") + 1))
numpedidopj = Trim(Mid(wbt.Sheets(i).Range("C20"), InStr(wbt.Sheets(i).Range("C20"), ":") + 1, Len(wbt.Sheets(i).Range("C20")) - InStr(wbt.Sheets(i).Range("C20"), ":") + 1))
wbt.Close False
'works perfectly until this point, here I wish to go back to the main workbook running the macro to start pasting the variables.
With wbd.Sheets(1)
.Range("A1048576").Select
End With
ActiveCell.End(xlUp).Offset(1, 0).Select
ActiveCell = nomecliente
ActiveCell.Offset(0, 1) = cpfcliente
ActiveCell.Offset(0, 2) = datacliente
ActiveCell.Offset(0, 3) = endcliente
ActiveCell.Offset(0, 4) = bairrocliente
ActiveCell.Offset(0, 5) = cepcliente
ActiveCell.Offset(0, 6) = cidadufcliente
ActiveCell.Offset(0, 7) = telecliente
ActiveCell.Offset(0, 8) = emailcliente
ActiveCell.Offset(0, 9) = obscliente
ActiveCell.Offset(0, 10) = endentrega
ActiveCell.Offset(0, 11) = bairroentrega
ActiveCell.Offset(0, 12) = cepentrega
ActiveCell.Offset(0, 13) = cidadufentrega
ActiveCell.Offset(0, 14) = telentrega
ActiveCell.Offset(0, 15) = emailentrega
ActiveCell.Offset(0, 16) = obsentrega
ActiveCell.Offset(0, 17) = obsgercliente
ActiveCell.Offset(0, 18) = boletoemailcliente
ActiveCell.Offset(0, 19) = boletoimpcliente
ActiveCell.Offset(0, 20) = lacradocliente
ActiveCell.Offset(0, 1).Select
Loop
End Sub