Tengo un archivo de excel que se genera con un atabla dinamica lo que pretendo con el siguiente codigo es enviar el libro activo pero como valores, solo que no lo consigo por que me marca un Error: Error en el metodo"SaveAS" de objeto_"Workbook"
Sub WorksheetLoop2()
Dim Current As Worksheet
For Each Current In Worksheets
Dim attBook$
attBook = Environ("temp") & "\" & Current.[A4].Value & ".xlsx"
If Dir(attBook) <> "" Then Kill attBook
With ActiveWorkbook
.SaveAs Filename:=attBook, FileFormat:=51
.Close False
End With
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = Current.[a1]
.CC = Current.[a2]
.BCC = ""
.Subject = Current.[A3]
.Body = " "
.Attachments.Add attBook
If .To = "" Then
.To = "al.com"
.Body = "Error, no se ha asignado un mail para "" " & Current.[A4]
End If
.send
End With
Set OutMail = Nothing
Set OutApp = Nothing
'Generamos un aviso de que el proceso termino
Next
MsgBox "Informes enviados"" " & Date
End Sub
Featured Replies
Archivado
Este tema está ahora archivado y está cerrado a más respuestas.
Buen dia
Tengo un archivo de excel que se genera con un atabla dinamica lo que pretendo con el siguiente codigo es enviar el libro activo pero como valores, solo que no lo consigo por que me marca un Error: Error en el metodo"SaveAS" de objeto_"Workbook"
Sub WorksheetLoop2()
Dim Current As Worksheet
For Each Current In Worksheets
Dim attBook$
attBook = Environ("temp") & "\" & Current.[A4].Value & ".xlsx"
Current.Copy
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
If Dir(attBook) <> "" Then Kill attBook
With ActiveWorkbook
.SaveAs Filename:=attBook, FileFormat:=51
.Close False
End With
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = Current.[a1]
.CC = Current.[a2]
.BCC = ""
.Subject = Current.[A3]
.Body = " "
.Attachments.Add attBook
If .To = "" Then
.To = "al.com"
.Body = "Error, no se ha asignado un mail para "" " & Current.[A4]
End If
.send
End With
Set OutMail = Nothing
Set OutApp = Nothing
'Generamos un aviso de que el proceso termino
Next
MsgBox "Informes enviados"" " & Date
End Sub