Docusign Request Signature by email - error in the base64 file content - base64

I'm developing some requests to Docusign API, and I'm receiving the error message { "errorCode": "UNSPECIFIED_ERROR", "message": "Invalid length for a Base-64 char array or string." } when I'm trying to send an file in the Send an electronic signature request via email method.
The following JSON that I'm sending in the request body:
{
"documents": [
{
"documentBase64": "base64 encoded file...",
"documentId": "1",
"fileExtension": "pdf",
"name": "FILENAME.pdf"
}
],
"emailSubject": "Assinatura de documento requerida",
"recipients": {
"signers": [
{
"email": "dfpdocusignteste#gmail.com",
"name": "DiegoLopes",
"recipientId": "1",
"routingOrder": "1",
"tabs": {
"dateSignedTabs": [
{
"anchorString": "signer1date",
"anchorYOffset": "-6",
"fontSize": "Size12",
"name": "Date Signed",
"recipientId": "1",
"tabLabel": "date_signed"
}
],
"fullNameTabs": [
{
"anchorString": "signer1name",
"anchorYOffset": "-6",
"fontSize": "Size12",
"name": "Full Name",
"recipientId": "1",
"tabLabel": "Full Name"
}
],
"signHereTabs": [
{
"anchorString": "signer1sig",
"anchorUnits": "mms",
"anchorXOffset": "0",
"anchorYOffset": "0",
"name": "Please sign here",
"optional": "false",
"recipientId": "1",
"scaleValue": 1,
"tabLabel": "signer1sig"
}
]
}
}
]
},
"status": "sent"
}
Some additional information. I'm doing this requests by asp classic calls. It's already working fine to get login information and the token data. this is how I"m sending the requests.
<%
response.ContentType="application/json"
dim token
dim baseUrl
dim usrName
dim usrPwd
dim usrIntegKey
dim receiptName
dim receiptEmail
dim docName
dim docContent
usrName = request.QueryString("username")
usrPwd = request.QueryString("password")
usrIntegKey = request.QueryString("integratorKey")
token = request.QueryString("token")
baseUrl = request.QueryString("baseUrl")
receiptName = request.form("receiptName")
receiptEmail = request.form("receiptEmail")
docName = request.form("docToSign")
docContent = replace(request.form("docContent"),"+", " ")
dataSent = ""
dataSent = dataSent & "{" & chr(13)
dataSent = dataSent & """documents"": [" & chr(13)
dataSent = dataSent & "{" & chr(13)
dataSent = dataSent & """documentBase64"": """ & docContent & """," & chr(13)
dataSent = dataSent & """documentId"": ""1""," & chr(13)
dataSent = dataSent & """fileExtension"": ""pdf""," & chr(13)
dataSent = dataSent & """name"": ""NDA.pdf""" & chr(13)
dataSent = dataSent & "}" & chr(13)
dataSent = dataSent & "]," & chr(13)
dataSent = dataSent & """emailSubject"": ""Assinatura de documento requerida""," & chr(13)
dataSent = dataSent & """recipients"": {" & chr(13)
dataSent = dataSent & """signers"": [" & chr(13)
dataSent = dataSent & "{" & chr(13)
dataSent = dataSent & """email"": """ & receiptEmail &"""," & chr(13)
dataSent = dataSent & """name"": """ & receiptName & """," & chr(13)
dataSent = dataSent & """recipientId"": ""1""," & chr(13)
dataSent = dataSent & """routingOrder"": ""1""," & chr(13)
dataSent = dataSent & """tabs"": {" & chr(13)
dataSent = dataSent & """dateSignedTabs"": [" & chr(13)
dataSent = dataSent & "{" & chr(13)
dataSent = dataSent & """anchorString"": ""signer1date""," & chr(13)
dataSent = dataSent & """anchorYOffset"": ""-6""," & chr(13)
dataSent = dataSent & """fontSize"": ""Size12""," & chr(13)
dataSent = dataSent & """name"": ""Date Signed""," & chr(13)
dataSent = dataSent & """recipientId"": ""1""," & chr(13)
dataSent = dataSent & """tabLabel"": ""date_signed""" & chr(13)
dataSent = dataSent & "}," & chr(13)
dataSent = dataSent & "]," & chr(13)
dataSent = dataSent & """fullNameTabs"": [" & chr(13)
dataSent = dataSent & "{" & chr(13)
dataSent = dataSent & """anchorString"": ""signer1name""," & chr(13)
dataSent = dataSent & """anchorYOffset"": ""-6""," & chr(13)
dataSent = dataSent & """fontSize"": ""Size12""," & chr(13)
dataSent = dataSent & """name"": ""Full Name""," & chr(13)
dataSent = dataSent & """recipientId"": ""1""," & chr(13)
dataSent = dataSent & """tabLabel"": ""Full Name""" & chr(13)
dataSent = dataSent & "}" & chr(13)
dataSent = dataSent & "]," & chr(13)
dataSent = dataSent & """signHereTabs"": [" & chr(13)
dataSent = dataSent & "{" & chr(13)
dataSent = dataSent & """anchorString"": ""signer1sig""," & chr(13)
dataSent = dataSent & """anchorUnits"": ""mms""," & chr(13)
dataSent = dataSent & """anchorXOffset"": ""0""," & chr(13)
dataSent = dataSent & """anchorYOffset"": ""0""," & chr(13)
dataSent = dataSent & """name"": ""Please sign here""," & chr(13)
dataSent = dataSent & """optional"": ""false""," & chr(13)
dataSent = dataSent & """recipientId"": ""1""," & chr(13)
dataSent = dataSent & """scaleValue"": 1," & chr(13)
dataSent = dataSent & """tabLabel"": ""signer1sig""" & chr(13)
dataSent = dataSent & "}" & chr(13)
dataSent = dataSent & "]" & chr(13)
dataSent = dataSent & "}" & chr(13)
dataSent = dataSent & "}" & chr(13)
dataSent = dataSent & "]" & chr(13)
dataSent = dataSent & "}," & chr(13)
dataSent = dataSent & """status"": ""sent""" & chr(13)
dataSent = dataSent & "}"
Set HttpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
HttpReq.open "POST", baseUrl & "/envelopes", False
HttpReq.SetRequestHeader "Authentication", "Bearer " & token
HttpReq.SetRequestHeader "Accept", "application/json"
HttpReq.SetRequestHeader "Content-type", "application/json"
HttpReq.SetRequestHeader "X-DocuSign-Authentication", "{ ""Username"": """ & usrName & """, ""Password"": """ & usrPwd & """, ""IntegratorKey"": """ & usrIntegKey & """ }"
response.Write(dataSent)
HttpReq.send(dataSent)
'response.Write(HttpReq.ResponseText)
%>
I've already calculated and the encoded value is a valid base64 content.
Can someone please help me on this?

I did a test using a simple PDF test file in my machine... this is the JS function that are encoding the file content:
var handleFileSelect = function(evt) {
var files = evt.target.files;
var file = files[0];
if (files && file) {
var reader = new FileReader();
reader.onload = function(readerEvt) {
var binaryString = readerEvt.target.result;
document.getElementById("hidden_doc").value = btoa(binaryString);
};
reader.readAsBinaryString(file);
}
var fullPath = document.getElementById('document').value;
if (fullPath) {
var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
fileName = fullPath.substring(startIndex);
if (fileName.indexOf('\\') === 0 || fileName.indexOf('/') === 0) {
fileName = fileName.substring(1);
}
}
};
Also, as you can see, I have a file input type to select the file:
<input type="file" id="document" accept=".pdf"/>

I've already solved the problem. My base64 function was wrong.
Now I'm using the following function and it's working fine:
function previewFile() {
var preview = document.getElementById("hidden_doc");
var file = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
reader.addEventListener("load", function () {
preview.value = reader.result.split(',')[1];
}, false);
if (file) {
reader.readAsDataURL(file);
}
var fullPath = document.getElementById('document').value;
if (fullPath) {
var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
fileName = fullPath.substring(startIndex);
if (fileName.indexOf('\\') === 0 || fileName.indexOf('/') === 0) {
fileName = fileName.substring(1);
}
}
}
Thanks all for your help.

Related

VBA Not processing .Body Line (or HTMLBody) in Macro

I am trying to make a macro that loops through a table on any sheet across a document and generated emails with info from that table to the individuals on each line. I think I got most of it to work but I can't figure out why .Body is no longer sending any information to outlook.
When I had shorter test messages it worked but now it isn't sending any body text to Outlook. My .To line is working fine as is my subject.
With OutMail
.To = Range("D" & i).Value
.CC = ""
.BCC = ""
.Subject = ActiveSheet.Name & " Service Insert"
'.HTMLBody = "Hi " & Range(C, i).Value & "<br><br>" & "Please see your Service Insert Below." & "<br>" & "<br>" _
& Range(S, 1).Value & "<br>" & "Services Played: " & Range(S, i).Value & "<br>" & "Doubling Services: " & Range("T" & i).Value & "<br>" & "Move Up Services: " & Range("W" & i).Value & " services from " & Range(Y, i) & "<br>" & "Solo Services: " & Range(Z, i).Value & "<br><br>" _
& Range(AA, 1).Value & "<br>" & "Services Played: " & Range(AA, i).Value & "<br>" & "Doubling Services: " & Range(AB, i).Value & "<br>" & "Move Up Services: " & Range(AE, i).Value & " services from " & Range(AG, i) & "<br>" & "Solo Services: " & Range(AH, i).Value & "<br><br>" _
& "Pay Period Totals" & "<br>" & "Total Leave Used: " & Range(F, i).Value & "<br>" & "Sick Leave Used: " & Range(i, i).Value & "<br>" & "Total Doubling Pay: " & Range(K, i).Value & "<br>" & "Total Move Up Pay: " & Range(L, i).Value & "<br>" & "Total Solo Pay: " & Range(M, i).Value & "<br>" & "Total Pay Correction: " & Range(N, i).Value & "<br>" & "Parking Reimbursement: " & Range(O, i).Value & "<br>" & "Mileage Reimbursement: " & Range(P, i).Value & "<br>" & "Travel Reimbursement: " & Range(Q, i).Value & "<br>" & "Total Additional Pay: " & Range(R, i).Value & "<br><br>" _
& "Season Totals" & "<br><br>" & "Total Season Services Used: " & Range(AZ, i).Value & "<br>" & "Sick Leave Remaining: " & Range(AY, i).Value & "<br><br>" & "Please let me know if you have any questions or concerns." & "<br><br>" & "Best, "
.Body = "Hi " & Range("C" & i).Value & vbNewLine & vbNewLine & "Please see your Service Insert Below." & vbNewLine & vbNewLine _
& Range("S1").Value & vbNewLine & "Services Played: " & Range("S" & i).Value & vbNewLine & "Doubling Services: " & Range("T" & i).Value & vbNewLine & "Move Up Services: " & Range("W" & i).Value & " services from " & Range("Y" & i) & vbNewLine & "Solo Services: " & Range("Z" & i).Value & vbNewLine & vbNewLine _
& Range("AA1").Value & vbNewLine & "Services Played: " & Range("AA" & i).Value & vbNewLine & "Doubling Services: " & Range("AB" & i).Value & vbNewLine & "Move Up Services: " & Range("AE" & i).Value & " services from " & Range("AG" & i) & vbNewLine & "Solo Services: " & Range("AH" & i).Value & vbNewLine & vbNewLine _
& "Pay Period Totals" & vbNewLine & "Total Leave Used: " & Range("F" & i).Value & vbNewLine & "Sick Leave Used: " & Range("I" & i).Value & vbNewLine & "Total Doubling Pay: " & Range("K" And i).Value & vbNewLine & "Total Move Up Pay: " & Range("L" And i).Value & vbNewLine & "Total Solo Pay: " & Range("M" And i).Value & vbNewLine & "Total Pay Correction: " & Range("N" And i).Value & vbNewLine & "Parking Reimbursement: " & Range("O" And i).Value & vbNewLine & "Mileage Reimbursement: " & Range("P" And i).Value & vbNewLine & "Travel Reimbursement: " & Range("Q" And i).Value & vbNewLine & "Total Additional Pay: " & Range("R" And i).Value & vbNewLine & vbNewLine _
& "Season Totals" & vbNewLine & vbNewLine & "Total Season Services Used: " & Range("AZ" & i).Value & vbNewLine & "Sick Leave Remaining: " & Range("AY" & i).Value & vbNewLine & vbNewLine & "Please let me know if you have any questions or concerns." & vbNewLine & vbNewLine & "Best, "
'.Attachments.Add ActiveWorkbook.FullName
.Display 'or use .Send
End With
On Error GoTo 0
This is the Body and HTMLBody I tried to make work, neither is sending any information, even failed cell searches to outlook.
I can show more of my the code if needed, for readability I hope this is enough.
Create a variable to create your body string by making some concatenations then assign the string to .Body. This way you can easily check your string and find an error by running step by step.
Dim emailBody as string: emailBody = ""
emailBody = emailBody & "Hi " & Range("C" & i).Value & vbNewLine & vbNewLine
emailBody = emailBody & "Please see your Service Insert Below." & vbNewLine & vbNewLine
emailBody = emailBody & Range("S1").Value & vbNewLine
...
With OutMail
...
.Body = emailBody
...
End With

VBA QueryTables not working with Yahoo Finance

I'm trying this simple Sub (in Excel 2019) to import tables from a specific Yahoo Finance page.
It works with other websites, but with Yahoo Finance, I keep getting the same message "This Web query returned no data. To change..........." and no data is extracted.
I couldn't figure out the reason.
Sub ImportTable()
Dim ws As Worksheet
Dim qt As QueryTable
Dim qurl As String
qurl = "https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT"
Set ws = worksheets.Add
Set qt = ws.QueryTables.Add( _
Connection:="URL;" & qurl, _
Destination:=Range("A1"))
With qt
.RefreshOnFileOpen = False
.Name = "test"
.WebFormatting = xlWebFormattingNone
.WebSelectionType = xlAllTables
.Refresh
End With
End Sub
You can instead set-up connections to the various tables which will add them to the data model (Alt + B + M). In the queries pane of data you can then chose where to load them to your workbook if you wish to see them. You can also just work with them in the data model and generate your final desired output.
Note:
The quicker way is, from ribbon, to do, data > from web > enter url > select tables of interest. This will set-up table connections without vba.
VBA:
Option Explicit
Public Sub AddYahooFinanceTableConnections()
Dim wb As ThisWorkbook
Set wb = ThisWorkbook
wb.Queries.Add Name:="Balance Sheet", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data10 = Source{10}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data10,{{""Total Cash (mrq)"", type text}, {""131.99B"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Cash Flow Statement", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data11 = Source{11}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data11,{{""Column1"", type text}, {""Column2"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Dividends & Splits", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data5 = Source{5}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data5,{{""Forward Annual Dividend Rate"", type text}, {""2.24"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Fiscal Year", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data6 = Source{6}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data6,{{""Column1"", type text}, {""Column2"", type date}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Income Statement", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data9 = Source{9}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data9,{{""Revenue (ttm)"", type text}, {""153.28B"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="People Also Watch", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data12 = Source{12}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data12,{{""Symbol"", type text}, {""Last Price"", type number}, {""Change"", type number}, {""% Change"", Percentage.Type}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Profitability", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data7 = Source{7}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data7,{{""Column1"", type text}, {""Column2"", Percentage.Type}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Share Statistics", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data4 = Source{4}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data4,{{""Avg Vol (3 month)"", type text}, {""30.36M"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Stock Price History", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data3 = Source{3}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data3,{{""Beta (5Y Monthly)"", type text}, {""0.79"", type number}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Table 0", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data0 = Source{0}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data0,{{""Column1"", type text}, {""Column2"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Table 1", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data1 = Source{1}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data1,{{""Column1"", type text}, {""Column2"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Connections.Add2 "Query - Balance Sheet", _
"Connection to the 'Balance Sheet' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Balance Sheet;Extended Properties=" _
, """Balance Sheet""", 6, True, False
wb.Connections.Add2 "Query - Cash Flow Statement", _
"Connection to the 'Cash Flow Statement' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Cash Flow Statement;Extended Properties=" _
, """Cash Flow Statement""", 6, True, False
wb.Connections.Add2 "Query - Dividends & Splits", _
"Connection to the 'Dividends & Splits' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Dividends & Splits;Extended Properties=" _
, """Dividends & Splits""", 6, True, False
wb.Connections.Add2 "Query - Fiscal Year", _
"Connection to the 'Fiscal Year' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Fiscal Year;Extended Properties=" _
, """Fiscal Year""", 6, True, False
wb.Connections.Add2 "Query - Income Statement", _
"Connection to the 'Income Statement' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Income Statement;Extended Properties=" _
, """Income Statement""", 6, True, False
wb.Connections.Add2 "Query - People Also Watch", _
"Connection to the 'People Also Watch' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=People Also Watch;Extended Properties=" _
, """People Also Watch""", 6, True, False
wb.Connections.Add2 "Query - Profitability", _
"Connection to the 'Profitability' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Profitability;Extended Properties=" _
, """Profitability""", 6, True, False
wb.Connections.Add2 "Query - Share Statistics", _
"Connection to the 'Share Statistics' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Share Statistics;Extended Properties=" _
, """Share Statistics""", 6, True, False
wb.Connections.Add2 "Query - Stock Price History", _
"Connection to the 'Stock Price History' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Stock Price History;Extended Properties=" _
, """Stock Price History""", 6, True, False
wb.Connections.Add2 "Query - Table 0", _
"Connection to the 'Table 0' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table 0;Extended Properties=" _
, """Table 0""", 6, True, False
wb.Connections.Add2 "Query - Table 1", _
"Connection to the 'Table 1' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table 1;Extended Properties=" _
, """Table 1""", 6, True, False
End Sub

Paste Workbook.Queries into arrays without pasting to sheet

So I have a bit of a problem with some query connections that I want to deal with inside an array because they can hold more rows than Excel can handle.
Option Explicit
Sub RefrescaConsultas()
EliminaConsultas
CreaConsultas
End Sub
Private Sub EliminaConsultas()
Dim Consulta As Object
For Each Consulta In ThisWorkbook.Queries
Consulta.Delete
Next Consulta
End Sub
Private Sub CreaConsultas()
Dim Mes As String: Mes = HMacro.Range("B2")
Dim Año As Long: Año = HMacro.Range("B1")
Dim MesNum As Byte: MesNum = Month(DateValue("01/" & Mes & "/2020"))
Dim RutaAccess As String: RutaAccess = Chr(34) & "\\ate2899cor01\reporting_administrativos\TELEFONICA\GP\Informe Evolucion Territorios\2020\Modelo Marzo´20\Inforrme Evolucion Ventas\Nuevo informe\BBDD\Actualiza Conversores.accdb" & Chr(34)
'Brutas
ThisWorkbook.Queries.Add "Brutas", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Brutas = Origen{[Schema="""",Item=""Brutas""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Rem" & _
"oveColumns(_Brutas,{""fx_proceso"", ""fx_estado_fin"", ""fx_devengo"", ""estado"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""faro"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", " & _
"""telefono"", ""segmento"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""producto_comision_alta_comercial"", ""producto_comision_actualizad" & _
"o"", ""importe_comision"", ""COD_T9"", ""rf_tq"", ""operacion"", ""sub_producto_destino_alta_comercial"", ""num_lineas_movil_tipo_fusion"", ""num_lineas_movil_planta"", ""in_fusion"", ""anul_15"", ""anul_30"", ""anul_60"", ""co_resolucion_sia"", ""resolucion_sia"", ""causa_anulacion"", ""fuente_origen"", ""cliente_nuevo"", ""in_servicio_tv""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Dat" & _
"e.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'TV
ThisWorkbook.Queries.Add "TV", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _TV = Origen{[Schema="""",Item=""TV""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.RemoveColum" & _
"ns(_TV,{""fx_proceso"", ""fx_estado_fin"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provincia_cliente"", ""ccaa_cli" & _
"ente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""no_sucursal"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""baja_prematura"", ""dias_baja"", ""producto_comision_alta_comercial"", ""importe_comision"", ""COD_T9"", ""rf_tq"", ""nu_administra"", ""fuente" & _
"_origen"", ""ds_fusion_origen"", ""ds_fusion_destino"", ""baja_prematura_8_mes_sig"", ""IN_PLANTA_8_MES_SIG"", ""CLIENTE_NUEVO""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Fusion
ThisWorkbook.Queries.Add "Fusion", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Fusion = Origen{[Schema="""",Item=""Fusion""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Rem" & _
"oveColumns(_Fusion,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""fx_instalacion"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""telefono"", ""segmento"", ""provincia" & _
"_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""matricula_origen"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""baja_prematura"", ""producto_comision_alta_comercial"", ""COD_T9"", ""valor_origen"", ""valor_destino"", ""rf_tq"", " & _
"""dif_dias_baja"", ""in_servicio_tv_origen"", ""in_servicio_tv_destino"", ""num_lineas_movil_tipo_fusion"", ""num_lineas_movil_planta"", ""CUC"", ""fuente_origen"", ""fx_alta_desco""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Inserciones
ThisWorkbook.Queries.Add "Inserciones", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Inserciones = Origen{[Schema="""",Item=""Inserciones""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" =" & _
" Table.RemoveColumns(_Inserciones,{""fx_proceso"", ""fx_estado_fin"", ""estado"", ""causa_estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""indicador_negocio_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provi" & _
"ncia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""cod_comision_alta_comercial"", ""producto_comision_alta_comercial"", ""importe_comision"", ""co_contrato"", ""co_plantari"", ""operado" & _
"r_origen"", ""operador_destino"", ""ICC"", ""LIQUIDABLE"", ""TARJETA_VIRTUAL"", ""NUMERO_REPETICIONES"", ""FUENTE_ORIGEN""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Prosegur
ThisWorkbook.Queries.Add "Prosegur", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Prosegur = Origen{[Schema="""",Item=""Prosegur""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table" & _
".RemoveColumns(_Prosegur,{""fx_proceso"", ""fx_estado_fin"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_solicitado"", ""indicador_negocio_solicitado"", ""producto_solicitado"", ""sub_producto_destino_solicitado"", ""subproducto_origen_solicitado"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_a" & _
"lta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""CUC"", ""tipo_doc"", ""id_fiscal"", ""telefono"", ""segmento"", ""localidad_cliente"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""matricula_origen"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta" & _
""", ""ccaa_venta"", ""territorio_venta"", ""pais_vendedor"", ""FechaGrab"", ""FechaGrabInci"", ""in_fusion"", ""tipo"", ""nu_administra"", ""unidades"", ""id_senializacion"", ""cod_comision_solicitado"", ""producto_comision_solicitado"", ""producto_comision_alta_comercial"", ""id_lead"", ""COD_T9"", ""rf_tq"", ""producto_comision_actualizado"", ""fuente_origen"", """ & _
"co_unico"", ""fecha_compromiso_ini"", ""fecha_alta_sistema"", ""Campo61"", ""Campo62"", ""Campo63""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Repos Móvil
ThisWorkbook.Queries.Add "Repos", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Repos = Origen{[Schema="""",Item=""Repos""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Remov" & _
"eColumns(_Repos,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_solicitado"", ""indicador_negocio_solicitado"", ""sub_producto_origen_alta_comercial"", ""subproducto_origen_alta_comercial"", ""cod_indicador_negocio_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_destino_alta_comercial"", " & _
"""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""localidad_cliente"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""matricula_origen"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""pais_vendedor" & _
""", ""in_fusion"", ""tipo"", ""operador_origen"", ""operador_destino"", ""in_terminal"", ""FechaGrab"", ""FechaGrabInci"", ""co_contrato_origen"", ""co_contrato_destino"", ""co_plantari_origen"", ""co_plantari_destino"", ""cod_comision_solicitado"", ""producto_comision_solicitado"", ""producto_comision_alta_comercial"", ""ICC"", ""FUENTE_ORIGEN"", ""Arpu_Origen"", " & _
"""Arpu_Destino"", ""unidades""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Terminales
ThisWorkbook.Queries.Add "Terminales", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Terminales = Origen{[Schema="""",Item=""Terminales""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = T" & _
"able.RemoveColumns(_Terminales,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provinci" & _
"a_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""producto_comision_alta_comercial"", ""importe_comision"", ""vendedor_entrega"", ""canal_venta_entrega"", ""agrupacion_canal_entrega"", """ & _
"canal_entrega"", ""detalle_canal_entrega"", ""co_proveedor_entrega"", ""no_empresa_entrega"", ""co_centro_venta_entrega"", ""no_sucursal_entrega"", ""provincia_venta_entrega"", ""territorio_venta_entrega"", ""tipo"", ""gama_terminal"", ""in_financiado"", ""nu_imei"", ""cod_campania"", ""FUENTE_ORIGEN"", ""Campo56"", ""Campo57"", ""Campo58"", ""Campo59"", ""Campo60""" & _
", ""Campo61""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Móvil
ThisWorkbook.Queries.Add "Movil", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Movil = Origen{[Schema="""",Item=""Movil""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Remov" & _
"eColumns(_Movil,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""subproducto_origen_alta_comercial"", ""co_modven"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", " & _
"""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""baja_prematura"", ""dif_dias_baja"", ""producto_comision_alta_comercial"", ""importe_comision"", ""in_terminal"", ""co_contrato"", ""co_plantari"", ""operador_origen"", ""operador_destino"", ""ICC"", ""fuen" & _
"te_origen""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'TMO
ThisWorkbook.Queries.Add "TMO", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _TMO = Origen{[Schema="""",Item=""TMO""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.RemoveCol" & _
"umns(_TMO,{""semana"", ""New_Territorio"", ""PAIS_TABLA"", ""MODO TABLA"", ""MODO TABLA TMO"", ""FX_LLAMADA"", ""NO_SEGMENTO"", ""NO_TERRITORIO"", ""NO_SUBTERRITORIO"", ""NO_PROVEEDOR"", ""NO_ORIGEN"", ""Terri_cliente"", ""Subterri_cliente"", ""ORIGEN"", ""NO_SEGMENTO_SKILL"", ""CO_GRABACION"", ""CLIENTE_NUEVO"", ""DS_SEGMENTO_ORGANIZATIVO"", ""B2C"", ""Idioma"", """ & _
"CO_TIPO_EMISION"", ""IN_AGENDADA"", ""CA_RECIBIDAS"", ""CA_LLAMADAA_VALIDAA"", ""CA_Atendidas_Entrantes"", ""CA_Aten_20seg"", ""CA_Conv_M20Seg"", ""CA_TMO"", ""CA_TMO_S"", ""CA_TME"", ""CA_Tr_Imputables"", ""CA_Transferidas"", ""CA_Salientes"", ""CA_AGENDADAS"", ""CA_TMO_AGENDADAS""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each [Mes] =" & _
MesNum & ")," & Chr(13) & "" & Chr(10) & " #""Filas filtradas1"" = Table.SelectRows(#""Filas filtradas"", each [Año] = " & Año & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas1"""
End Sub
The code is fairly simple, I've manually recorded Data->from data base->selected the data base->deleted some columns for each connection and filtered some data.
Now the workbook has all these connections that I need to work with, but pasting them into a sheet and then into an array might be a problem because some of them are more than 1M rows... Any Insight on how to achieve this?
Specifications and Limits for Excel Worksheets and Workbooks
Total number of rows and columns in a worksheet :
1,048,576 rows and 16,384 columns
so you may have to add a clause to limit the number of rows: select TOP 1000 in your SQL request
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Customer;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT TOP 10OO fx_proceso FROM [Prosegur]")

I keep getting the error message "subscript out of range",

when I compare a table and a dump text file. I would load a powerbi to get a text file and then compareit with my already created table, so as to displaye the matching onesThis is the code that I ve been using to load the dump and compare it with the already created table
ActiveWorkbook.Queries.Add Name:="dump", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Csv.Document(File.Contents(""xx:\location.txt""),[Delimiter=""#(tab)"", Columns=17, Encoding=65001, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & " #""Promoted Headers"" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(#""Promoted Headers"",{{""market"", Int64.Type}, {""category"", Int64.Type}, {""brand"", type text},{""brand status"", type text}, {""vendor_code"", type text}, {""status_last_update_date"", Int64.Type}})," & Chr(13) & "" & Chr(10) & " #""Filtered Rows"" = Table.SelectRows(#""Changed Type"", each ([brand status] <> """" and [brand_status] <> ""Audit"" and [brand status] <> ""SUPPRESSED""))," & Chr(13) & "" & Chr(10) & " " & _
Workbooks("Sheet2").Connections.Add2 "Query - dump", _
"Connection to the 'dump' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""us dump"";Extended Properties=""""" _
, "SELECT * FROM [us dump]", 2
ActiveWorkbook.Queries.Add Name:="Table1", Formula:= _

Send email to various addresses from cells

I have in "Sheet1" numerous email addresses, in columns K, M, O, Q, S, U, W, Y, AA.
I want to create an email that will be sent to all the addresses taken from the last row in Sheet1. Same for data in email body taken from last row.
Dim MonOutlook As Object
Dim MonMessage As Object
Dim EmailTo As String
With Worksheets("Sheet1")
EmailTo = .Range("K" & ligne) & ";" & .Range("M" & ligne) & ";" & .Range("O" & ligne) & ";" & .Range("Q" & ligne) & ";" & .Range("S" & ligne) & ";" & .Range("U" & ligne) & ";" & .Range("W" & ligne) & ";" & .Range("Y" & ligne) & ";" & .Range("AA" & ligne)
End With
Set MonOutlook = CreateObject("Outlook.Application")
Set MonMessage = MonOutlook.CreateItem(0)
MonMessage.To = ""
MonMessage.Cc = ""
MonMessage.Bcc = EmailTo
MonMessage.Subject = "Rate request" & " " & "for" & " " & ThisWorkbook.Sheets("Sheet1").Range("B" & ligne)
MonMessage.body = "Hello,"
Chr (13) & Chr(13) & "Please send me rate for" & " " & ThisWorkbook.Sheets("Sheet1").Range("G" & ligne) & " " & "rooms on basis" & " " & ThisWorkbook.Sheets("Sheet1").Range("H" & ligne) & _
Chr(13) & Chr(13) & "in hotel:" & " " & ThisWorkbook.Sheets("Sheet1").Range("J" & ligne) & _
Chr(13) & Chr(13) & "for the period" & " " & ThisWorkbook.Sheets("suivi").Range("C" & ligne) & " " & ThisWorkbook.Sheets("Sheet1").Range("D" & ligne) & _
Chr(13) & Chr(13) & "Thank you!" & _
Chr(13) & Chr(13) & Application.UserName & " " & "-" & " " & "x Tours"
MonMessage.Display
With ThisWorkbook.Sheets("Sheet1").Range("AB" & ligne)
.Value = Date
.NumberFormat = "dd/mm/yyyy"
End With
ActiveWorkbook.Save
Try the code below, explanations inside the code's comments.
Option Explicit
Sub EmailContactsLastRow()
Dim MonOutlook As Object
Dim MonMessage As Object
Dim EmailSht As Worksheet
Dim EmailTo As String
Dim ligne As Long
' set the worksheet object
Set EmailSht = ThisWorkbook.Sheets("Sheet1")
With EmailSht
ligne = .Cells(.Rows.Count, "K").End(xlUp).Row ' get last row with data in column K
EmailTo = .Range("K" & ligne) & ";" & .Range("M" & ligne) & ";" & .Range("O" & ligne) & ";" & _
.Range("Q" & ligne) & ";" & .Range("S" & ligne) & ";" & .Range("U" & ligne) & ";" & _
.Range("W" & ligne) & ";" & .Range("Y" & ligne) & ";" & .Range("AA" & ligne)
End With
Set MonOutlook = CreateObject("Outlook.Application")
Set MonMessage = MonOutlook.CreateItem(0)
With MonMessage
.To = ""
.Cc = ""
.Bcc = EmailTo
.Subject = "Rate request" & " " & "for" & " " & EmailSht.Range("B" & ligne)
.body = "Hello,"
Chr (13) & Chr(13) & "Please send me rate for" & " " & EmailSht.Range("G" & ligne) & " " & "rooms on basis" & " " & EmailSht.Range("H" & ligne) & _
Chr(13) & Chr(13) & "in hotel:" & " " & EmailSht.Range("J" & ligne) & _
Chr(13) & Chr(13) & "for the period" & " " & EmailSht.Range("C" & ligne) & " " & EmailSht.Range("D" & ligne) & _
Chr(13) & Chr(13) & "Thank you!" & _
Chr(13) & Chr(13) & Application.UserName & " " & "-" & " " & "x Tours"
.Display ' <-- this displays the email. not sending it
.send ' <-- this sends the email out
End With
With EmailSht.Range("AB" & ligne)
.Value = Date
.NumberFormat = "dd/mm/yyyy"
End With
ThisWorkbook.Save
End Sub

Resources