Guardar libro de excel generado protegiendo hojas.
Hola a todo el mundo.
Con esta macro adaptada por mi de la pagina del guru Ron de Bruin, genero un libro nuevo con hojas seleccionadas previamente y lo envío por correo mediante outlook express.
El libro desde donde se genera, naturalmente, tiene macros. Esta en formato ".xlsm" y lo he adaptado a ".xls"
Lo que no soy capaz, es de que el archivo que me envía, me lo guarde en una ruta especifica, y que proteja las hojas, para que no pueda ser modificado por el remitente.
Adjunto código:
Sub Mail_Sheets_Array() 'Working in 97-2010 Dim FileExtStr As String Dim FileFormatNum As Long Dim Sourcewb As Workbook Dim Destwb As Workbook Dim TempFilePath As String Dim TempFileName As String Dim sh As Worksheet Dim TheActiveWindow As Window Dim TempWindow As Window Dim I As Long With Application .ScreenUpdating = False .EnableEvents = False End With Set Sourcewb = ActiveWorkbook 'Copy the sheets to a new workbook 'We add a temporary Window to avoid the Copy problem 'if there is a List or Table in one of the sheets and 'if the sheets are grouped With Sourcewb Set TheActiveWindow = ActiveWindow Set TempWindow = .NewWindow .Sheets(Array("Hoja Nueva", "Hoja Nueva (2)", "Hoja Nueva (3)")).Copy End With 'Close temporary Window TempWindow.Close Set Destwb = ActiveWorkbook 'Determine the Excel version and file extensión/format With Destwb If Val(Application.Version) < 12 Then 'You use Excel 97-2003 FileExtStr = ".xls": FileFormatNum = -4143 Else 'You use Excel 2007-2010, we exit the sub when your answer is 'NO in the security dialog that you only see when you copy 'an sheet from a xlsm file with macro's disabled. If Sourcewb.Name = .Name Then With Application .ScreenUpdating = True .EnableEvents = True End With MsgBox "Your answer is NO in the security dialog" Exit Sub Else FileExtStr = ".xls": FileFormatNum = 56 End If End If End With ' 'Change all cells in the worksheets to values if you want ' For Each sh In Destwb.Worksheets ' sh.Select ' With sh.UsedRange ' .Cells.Copy ' .Cells.PasteSpecial xlPasteValues ' .Cells(1).Select ' End With ' Application.CutCopyMode = False ' Destwb.Worksheets(1).Select ' Next sh 'Save the new workbook/Mail it/Delete it TempFilePath = Environ$("temp") & "\" TempFileName = Sheets("Hoja Nueva").Range("bm2") With Destwb .SaveAs TempFilePath & TempFileName & FileExtStr, _ FileFormat:=FileFormatNum On Error Resume Next For I = 1 To 3 .SendMail Sheets("hoja Nueva").Range("BM1"), _ Sheets("Hoja Nueva").Range("bm2") If Err.Number = 0 Then Exit For Next I On Error GoTo 0 .Close SaveChanges:=False End With 'Delete the file you have send Kill TempFilePath & TempFileName & FileExtStr With Application .ScreenUpdating = True .EnableEvents = True End With End Sub
Agradezco cualquier ayuda para poder realizar este preyecto.
Gracias por vuestro tiempo y saludos.