0 Replies Latest reply: Jul 5, 2013 7:05 AM by Ignacio Cifuentes RSS

    Run Macros on server side

    Ignacio Cifuentes

      Hi i have the following macro that generates a report in pdf and send it by mail

       

      Sub GenerarPDF

      'Aplico la Macro

      ActiveDocument.RecallDocBookmark "Spain"

      'Creo el PDF

      Set PDFCreator = CreateObject("PDFCreator.clsPDFCreator")

      PDFCreator.cOption("UseAutosave") = 1 'Enable autosave

      PDFCreator.cOption("UseAutosaveDirectory") = 1 'Use a specific save directory

      PDFCreator.cOption("AutosaveDirectory") = "C:\Users\User1\Desktop\Informes" ' Set autosave directory

      PDFCreator.cOption("AutosaveFormat") = 0 'Use PDF file type (.PDF extension) 1= PNG

      PDFCreator.cOption("AutosaveFilename") = "Spain "&ActiveDocument.Variables("Fase_Max_Año").GetContent.String 'set the filename, optionally you can get the Caption of the object and use it as Filename

      PDFCreator.cPrinterStop = FALSE

      ' Export to PDF File

      ActiveDocument.PrintDocReport "RP01", "PDFCreator"

      End Sub

       

      Sub EnviarCorreo

       

      Servidor = "smtp.gmail.com"

      User = "Usuario"

      Password = "Password"

       

       

      'ENVIO DE CORREO

      'España

      ActiveDocument.RecallDocBookmark "Spain"

      Set objMessage = CreateObject("CDO.Message")

      objMessage.Subject = "Qlikview Informes España " &now()

      objMessage.From = "home@gmail.com"

      'objMessage.To = "example@example.com"

      objMessage.TextBody = "Se adjunta el informe España "&ActiveDocument.Variables("Fase_Max_Año").GetContent.String&"."

      objMessage.AddAttachment  "C:\Users\User1\Desktop\Informes\Spain "&ActiveDocument.Variables("Fase_Max_Año").GetContent.String&".pdf"

      '==This section provides the configuration information for the remote SMTP server.

      '==Normally you will only change the server name or IP.

      objMessage.Configuration.Fields.Item _

      ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

      'Name or IP of Remote SMTP Server

      objMessage.Configuration.Fields.Item _

      ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Servidor

      'Server port (typically 25)

      objMessage.Configuration.Fields.Item _

      ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

      objMessage.Configuration.Fields.Item _

      ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

      objMessage.Configuration.Fields.Item _

      ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true

      objMessage.Configuration.Fields.Item _

      ("http://schemas.microsoft.com/cdo/configuration/sendusername") = User

      objMessage.Configuration.Fields.Item _

      ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Password

      objMessage.Configuration.Fields.Update

      '==End remote SMTP server configuration section==

      objMessage.Send

      End Sub

       

      The problem is that when i click on the button that runs this macro is that it execute in the local computer not in the server as desired

      How can i do to run the macro on the server side