stefano
Gebruiker
- Lid geworden
- 22 mei 2004
- Berichten
- 865
In een poging een 'range' in een werkblad te mailen (en niet het volledige bestand) gaat de opmaak binnen die range verloren. Gezien ik weinig verstand heb van vba raak ik er niet uit hoe ik dit kan corrigeren/omzeilen. In bijlage het bestand. Gelieve je eigen mailadres in te geven in cel Q7 aub 

Code:
Sub mailen_range()
Dim source As Range
Dim ColumnCount As Long
Dim FirstColumn As Long
Dim ColumnWidthArray() As Double
Dim lIndex As Long
Dim lCount As Long
Dim dest As Workbook
Dim i As Long
Dim strdate As String
Dim pad As String
Dim bestandsnaam As String
Application.ScreenUpdating = False
Set source = Nothing
On Error Resume Next
'hieronder de range die in het nieuwe blad moet komen, graag met de originele opmaak
Range("A1:w35").Select
Set source = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If source Is Nothing Then
MsgBox "The selection is not a range or the sheet is protect, please correct and try again.", vbOKOnly
Application.ScreenUpdating = True
Exit Sub
End If
ColumnCount = Selection.Columns.Count
FirstColumn = Selection.Cells(1).Column - 1
ReDim ColumnWidthArray(1 To ColumnCount)
lIndex = 0
For lCount = 1 To ColumnCount
If Columns(FirstColumn + lCount).Hidden = False Then
lIndex = lIndex + 1
ColumnWidthArray(lIndex) = Columns(FirstColumn + lCount).ColumnWidth
End If
Next lCount
Set dest = Workbooks.Add(xlWBATWorksheet)
source.Copy
With dest.Sheets(1)
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
For i = 1 To lIndex
.Columns(i).ColumnWidth = ColumnWidthArray(i)
Next
End With
With dest
.SaveAs "Stefano" & ".xlsx"
.SendMail Range("Q7"), "Stefano's Pizza - bloem Stefano - " & Format$(Range("b32"))
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Range("A1").Select
Application.ScreenUpdating = True
End Sub
[ATTACH]291835.vB[/ATTACH]