1

I have an Excel worksheet where I can insert Data into a MS SQL Database. When closing this worksheet, a mail with the sql-script attached should be generated and send automatically. The script includes all the create table, sequences and insert statements.

I can generate the sql script manually in the MS SQL Studio, but maybe there´s a method (here: generate_sql_script) to generate the script automatically.

Here´s my code for generating the mail:

Dim objOutlook, objMail, sql_Script As Object
Set objOutlook = CreateObject("Outlook.Application")

sql_Script = generate_sql_script

With objMail
    .To = "[email protected]"
    .Subject = "new sql script attached"
    .Body = "Dear Sir or madam..."
    .Attachments.Add sql_Script
    .Send
End With

Thanks for any help in advance.

11
  • Are you talking about MS SQL? So tag your question correctly and remove the MySql tag Commented Apr 3, 2018 at 13:44
  • How are you expecting to generate this "sqp-script"? Commented Apr 3, 2018 at 13:57
  • @TrevorD nothing really. I tried to "record the macro" in Excel, but it didn´t work. I don´t know if my idea of writing a method, that generates the script for me is even possible. Commented Apr 3, 2018 at 14:03
  • @nacho yes I´m talking about MS SQL.. sorry for the mistake. Commented Apr 3, 2018 at 14:05
  • @Zac THAT´S my question. Commented Apr 3, 2018 at 14:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.