Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Ribeiro
Specialist
Specialist

Como fechar o editor do macro ao execulta-lo

Não estou conseguindo fechar a tela do editor, quando executo o macro.

Alguma dica de como não deixa-lo abrir.

2015-12-16_15-22-09.png

2015-12-16_15-21-38.png

Neves
1 Solution

Accepted Solutions
afurtado
Partner Ambassador/MVP
Partner Ambassador/MVP

Agnaldo,  se nao vai ser mandado email pela macro, por teoria serve o codigo abaixo, bastando mudar o ID do relatorio

sub PrintReport

  ActiveDocument.PrintDocReport "RP01","Teste"

  Set WSHShell = CreateObject("WScript.Shell")

  fln = "S:\BI\TecnoFlex\PDF\myreport.pdf"

  RegKey = "HKEY_CURRENT_USER\Software\QlikViewPDF\"

  WSHShell.RegWrite RegKey & "BypassSaveAs", 1

  WSHShell.RegWrite RegKey & "OutputFile", fln

  ActiveDocument.GetApplication.Sleep 2000

  WSHShell.RegWrite RegKey & "BypassSaveAs", 0

  WSHShell.RegWrite RegKey & "OutputFile", ""

  Set WSHShell = nothing

end sub

furtado@farolbi.com.br

View solution in original post

5 Replies
afurtado
Partner Ambassador/MVP
Partner Ambassador/MVP

Agnaldo, boa tarde.

Ele não para no código. Se parou é porque tem erro. Vai comentando partes ate achar a parte errada.....(seria uma forma.....)

furtado@farolbi.com.br
Ribeiro
Specialist
Specialist
Author

Engraçado Alessandro,

Ele está funcionando para mim.

Unica coisa que aparece é editor.

Imagino que esteja com erro.

Mas não sei onde acha-los.

sub PrintReport

  Set WSHShell = CreateObject("WScript.Shell")

  fln = "S:\BI\TecnoFlex\PDF\myreport.pdf"

  RegKey = "HKEY_CURRENT_USER\Software\QlikViewPDF\"

  WSHShell.RegWrite RegKey & "BypassSaveAs", 1

  WSHShell.RegWrite RegKey & "OutputFile", fln

  ActiveDocument.GetApplication.Sleep 2000

  WSHShell.RegWrite RegKey & "BypassSaveAs", 0

  WSHShell.RegWrite RegKey & "OutputFile", ""

  Set WSHShell = nothing

end sub

function GetVariable(varName)

        Dim v

        set v = ActiveDocument.Variables(varName)

        GetVariable = v.GetContent.String

end function

Sub ExecMacro()

        'ActiveDocument.Reload       

        Envio()

        'ActiveDocument.Save

        'ActiveDocument.GetApplication.Quit

        'ActiveDocument.GetApplication.Close       

End Sub

Sub Envio()

  Set TabelaEmails = ActiveDocument.Fields("Gerente").GetPossibleValues(1000)

  For contEmail = 0 to TabelaEmails.Count - 1

  ActiveDocument.Fields("Gerente").Select TabelaEmails.Item(contEmail).Text

        ActiveDocument.PrintDocReport "RP01","Gerente"

      

  PrintReport()

  ActiveDocument.GetApplication.Sleep 2000

  Set filesys = Nothing

        Set filesys = CreateObject("Scripting.FileSystemObject")

  If filesys.FileExists("C:\tmp\Relatório Gerente - " & TabelaEmails.Item(contEmail).Text & ".pdf") then

  filesys.DeleteFile "C:\tmp\Relatório Gerente - " & TabelaEmails.Item(contEmail).Text & ".pdf"

  End If

  ActiveDocument.GetApplication.Sleep 1000

  Set filesys = Nothing

      

  Set filesys = CreateObject("Scripting.FileSystemObject")

  If filesys.FileExists("C:\tmp\QlikView Printing.pdf") then

    filesys.MoveFile "C:\tmp\QlikView Printing.pdf", "C:\tmp\Relatório Gerente - " & TabelaEmails.Item(contEmail).Text & ".pdf"

  End If

  ActiveDocument.GetApplication.Sleep 1000

  vRepositorio  = GetVariable("vRepositorio")

  Porta         = GetVariable("smtpPorta")

  Server        = GetVariable("smtpServer")

  Usuario       = GetVariable("smtpUser")

  Senha         = GetVariable("smtpPWD")

  Origem        = GetVariable("smtpOrigem")

  Set objEmail = CreateObject("CDO.Message")

  Set objConf = objEmail.Configuration

  Set objFlds = objConf.Fields

  With objFlds

  '---------------------------------------------------------------------

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

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

  if len(Usuario) > 0 then

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

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

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

  else

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

  end if

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

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

  .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

  .Update

  '---------------------------------------------------------------------

  End With

  Destinatarios     = TabelaEmails.Item(contEmail).Text

  'Destinatarios     = "teste@teste.ind.br"

  objEmail.To       = Destinatarios

  'objEmail.CC       = "nn@mm.com.br"

  objEmail.From     = "mmmm@nnnn.com.br"

  objEmail.Subject  = "Gerencia : " & TabelaEmails.Item(contEmail).Text

  objEmail.HTMLBody = ""

  objEmail.AddAttachment "C:\tmp\Relatório Gerente - " & TabelaEmails.Item(contEmail).Text & ".pdf"

  objEmail.Send

        Set filesys = CreateObject("Scripting.FileSystemObject")

  If filesys.FileExists("C:\tmp\Relatório Gerente - " & TabelaEmails.Item(contEmail).Text & ".pdf") then

  filesys.DeleteFile "C:\tmp\Relatório Gerente - " & TabelaEmails.Item(contEmail).Text & ".pdf"

  End If

  ActiveDocument.GetApplication.Sleep 2000

  Set filesys = Nothing

  Next

  ActiveDocument.Fields("Gerente").Clear ' Limpar Filtro por Email

End Sub

Neves
Ribeiro
Specialist
Specialist
Author

Alessandro,

eu não preciso do email no script.

Já que o fiz no PDFCreator.

como eu retiro esta parte.

já que o processo está enviado corretamente.

Apenas o editor está aparecendo, acredito eu que seja pelo email.

Neves
afurtado
Partner Ambassador/MVP
Partner Ambassador/MVP

Agnaldo,  se nao vai ser mandado email pela macro, por teoria serve o codigo abaixo, bastando mudar o ID do relatorio

sub PrintReport

  ActiveDocument.PrintDocReport "RP01","Teste"

  Set WSHShell = CreateObject("WScript.Shell")

  fln = "S:\BI\TecnoFlex\PDF\myreport.pdf"

  RegKey = "HKEY_CURRENT_USER\Software\QlikViewPDF\"

  WSHShell.RegWrite RegKey & "BypassSaveAs", 1

  WSHShell.RegWrite RegKey & "OutputFile", fln

  ActiveDocument.GetApplication.Sleep 2000

  WSHShell.RegWrite RegKey & "BypassSaveAs", 0

  WSHShell.RegWrite RegKey & "OutputFile", ""

  Set WSHShell = nothing

end sub

furtado@farolbi.com.br
Ribeiro
Specialist
Specialist
Author

Alessandro,

Muito obrigado, eu desenvolvo, para pequenas empresas.

O máximo que enviou e para o gerente e o dono.

A ferramenta PDFCreator. Faz tudo sozinho

O Qlikview faz o milagre o pdfCreator entrega o milagre.

Boa Noite.

Agnaldo

2015-12-16_21-49-25.jpg

2015-12-16_21-49-55.jpg

Neves