Avatar billede AOT1977 Praktikant
20. januar 2012 - 13:31 Der 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

/Allan
Avatar billede AOT1977 Praktikant
22. januar 2012 - 15:57 #1
ingen forslag?
Avatar billede jens48 Ekspert
25. januar 2012 - 04:09 #2
Prøv at se på
http://msdn.microsoft.com/en-us/library/ff519602(v=office.11).aspx#odc_office_UseExcelObjectModeltoSendMailPart2_MailingRangeSelectionBody

Der er der en makro, jeg med lidt modifikationer kunne få til at virke, som du ønsker.
Avatar billede AOT1977 Praktikant
25. januar 2012 - 11:38 #3
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
Avatar billede jens48 Ekspert
26. januar 2012 - 02:02 #4
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
Avatar billede AOT1977 Praktikant
26. januar 2012 - 10:58 #5
den kommer bare op og siger : The selection is not a range or the sheet is protected. Please correct and try again.

hvad mangler jeg at gøre
Avatar billede AOT1977 Praktikant
26. januar 2012 - 13:23 #6
det den skal kopier til body er Range("A1:O33")

ikke R84, R84 =(A1:O33) giver #VÆRDI!
Avatar billede AOT1977 Praktikant
26. januar 2012 - 14:02 #7
Jeg har leget lidt og har klaret det, ved ikke lige hvad  men det virker nu griner så mange tak jens48
Avatar billede Ny bruger Nybegynder

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.

Loading billede Opret Preview
Kategori
Excel kurser for alle niveauer og behov – find det kursus, der passer til dig

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester