20. januar 2012 - 13:31Der er
6 kommentarer og 1 løsning
Hjælp til mail link i excel
Hej
Jeg har lavet et ark der indsamler date i et skema, dette skema vil jeg gerne sende i en e-mail, så jeg har lavet et mail link:
I celle R82 står den e-mail der skal sendes til. I celle R83 står der emne på e-mail I celle R84 skal e-mailens indhold så stå =skema der fylder fra (A1:O33) I celle R85 samler jeg så en del at mail link, ="Mailto:"&R82&"?Subject="&R83&"&Body="&R84 I celle A43 stå =HYPERLINK(R85;"KLIK HER for at oprette en e-mail")
Nu kommer mit problem så mit skema som skal stå i body på e-mail er lidt større en bare en celle.
Hvordan få en mit skema med i e-mail, det kan godt være der skal laves på anden måde end det her jeg har lavet, men kom frisk
Denne side indeholder artikler med forskellige perspektiver på Identity & Access Management i private og offentlige organisationer. Artiklerne behandler aktuelle IAM-emner og leveres af producenter, rådgivere og implementeringspartnere.
Nu er jeg ikke lige så god til makro, men det må være denne du mener:
Sub Mail_Selection_Range_Outlook_Body() ' You need to use this module with the RangetoHTML subroutine. ' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, and Outlook 2010. Dim rng As Range Dim OutApp As Object Dim OutMail As Object
Set rng = Nothing On Error Resume Next ' Only send the visible cells in the selection. Set rng = Selection.SpecialCells(xlCellTypeVisible) ' You can also use a range with the following statement. ' Set rng = Sheets("YourSheet").Range("D4:D12").SpecialCells(xlCellTypeVisible) On Error GoTo 0
If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected. " & _ vbNewLine & "Please correct and try again.", vbOKOnly Exit Sub End If
With Application .EnableEvents = False .ScreenUpdating = False End With
Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0)
On Error Resume Next With OutMail .To = "ron@debruin.nl" .CC = "" .BCC = "" .Subject = "This is the Subject line" .HTMLBody = RangetoHTML(rng) ' In place of the following statement, you can use ".Display" to ' display the e-mail message. .Send End With On Error GoTo 0
With Application .EnableEvents = True .ScreenUpdating = True End With
Set OutMail = Nothing Set OutApp = Nothing End Sub
Med disse tilretninger skulle de være OK. Begge makroer er nødvendige. ---- Sub Mail_Selection_Range_Outlook_Body() Dim rng As Range Dim OutApp As Object Dim OutMail As Object
Set rng = Nothing On Error Resume Next Set rng = Range(Range("R84").Value).SpecialCells(xlCellTypeVisible) On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected. " & _ vbNewLine & "Please correct and try again.", vbOKOnly Exit Sub End If
With Application .EnableEvents = False .ScreenUpdating = False End With
Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0)
On Error Resume Next With OutMail .To = Cells(82, 18) .CC = "" .BCC = "" .Subject = Cells(83, 18) .HTMLBody = RangetoHTML(rng) .Send End With On Error GoTo 0
With Application .EnableEvents = True .ScreenUpdating = True End With
Set OutMail = Nothing Set OutApp = Nothing End Sub
Function RangetoHTML(rng As Range) 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" 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 TempWB.PublishObjects.Add( _ SourceType:=xlSourceRange, _ Filename:=TempFile, _ Sheet:=TempWB.Sheets(1).Name, _ Source:=TempWB.Sheets(1).UsedRange.Address, _ HtmlType:=xlHtmlStatic) .Publish (True) End With 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=") TempWB.Close savechanges:=False Kill TempFile Set ts = Nothing Set fso = Nothing Set TempWB = Nothing End Function
Jeg har leget lidt og har klaret det, ved ikke lige hvad men det virker nu griner så mange tak jens48
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.