Página 1 de 1

Email automático com erro em horas negativas

Enviado: 01 Jun 2017 às 01:24
por ThiagoN
bom dia

estou enviando um email automático referente a banco de horas, mas as horas negativas ficam desconfiguradas. "###############", o que devo fazer?

segue cod abaixo.
Sub Macro4()

UsuarioRede vUsuario

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Dim vAgora As Date
Set rng = Nothing


Sheets("Banco de Horas").Select
Range("A2").Select
Selection.End(xlDown).Select
vLinNFE = ActiveCell.Row



Set rng = Sheets("Banco de Horas").Range("C4:I25").SpecialCells(xlCellTypeVisible)
'Set rng = Sheets("Assinatura").Range("A1:B5").SpecialCells(xlCellTypeVisible)


Set OutApp = CreateObject("OutLook.application")
Set OutMail = OutApp.CreateItem(0)

Dim vCorpo As String


sHTML = sHTML & "<p style=""font-size:11pt"">Segue abaixo informações referente Banco de Horas / Caso o Funcionario esteja em setor errado me avise / As horas negativas não vão aparecer nesse primeiro e-mail. </p>"

With OutMail

'.to = ""
.To = ""
.CC = ""
.Subject = "Banco de Horas CS CD SPI"
.HTMLBody = sHTML & RangetoHTML(rng)
'& "<html><body> <br>Atenciosamente.<br><br><img src=file:F:\SIGNATURE\Logo.Jpg align=top> Carlos Henrique Arantes FIod<br>Operador de Computador Sr.<br></body></html>"

'& Signature
'.Display
.Send
End With


End Sub

Email automático com erro em horas negativas

Enviado: 01 Jun 2017 às 11:15
por Reinaldo
Creio eu que ao acrescentar novo Workbook, esse por padrão vem com o sistema de data 1900 o que gera o "erro".
Experimente alterar sua Funçãoto Html conforme abaixo
Código: Selecionar todos
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2010
    Dim fso As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook
 
    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
 
    'Copy the range and create a new workbook to past the data in
    rng.Copy
    Set TempWB = Workbooks.Add(1)

    With TempWB.Sheets(1)
        .Cells(1).PasteSpecial Paste:=8
        .Cells(1).PasteSpecial xlPasteValues, , False, False
        .Cells(1).PasteSpecial xlPasteFormats, , False, False
        .Cells(1).Select
        Application.CutCopyMode = False
        On Error Resume Next
        .DrawingObjects.Visible = True
        .DrawingObjects.Delete
        On Error GoTo 0
    End With
    With ActiveWorkbook
        .Date1904 = True
    End With
 
    'Publish the sheet to a htm file
    With TempWB.PublishObjects.Add( _
         SourceType:=xlSourceRange, _
         Filename:=TempFile, _
         Sheet:=TempWB.Sheets(1).Name, _
         Source:=TempWB.Sheets(1).UsedRange.Address, _
         HtmlType:=xlHtmlStatic)
        .Publish (True)
    End With
 
    'Read all data from the htm file into RangetoHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = ts.readall
    ts.Close
    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                          "align=left x:publishsource=")
 
    'Close TempWB
    TempWB.Close savechanges:=False
 
    'Delete the htm file we used in this function
    Kill TempFile
 
    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
End Function