+ Reply to Thread
Results 1 to 5 of 5

Help with macro to paste copied tabs in excel directly in mail

  1. #1
    Registered User
    Join Date
    07-27-2020
    Location
    Denmark
    MS-Off Ver
    2019
    Posts
    19

    Help with macro to paste copied tabs in excel directly in mail

    I have this simple macro that needs to take specific tabs (dynamic), copy and send them in an email - But it keeps taking my reference mail from A1 in the paste - Someone who can see the fail or lead me in the right direction?

    Note that the answer is not to put the reference mail in another tab as in the real excel sheet there needs to information above the copied.


    code

    Sub esendtable()
    Dim outlook As Object
    Dim newEmail As Object
    Dim xInspect As Object
    Dim pageEditor As Object
    Set outlook = CreateObject("Outlook.Application")
    Set newEmail = outlook.CreateItem(0)
    With newEmail
    .To = Sheet1.Range("A1").Text
    .CC = ""
    .BCC = ""
    .Subject = "Personoplysninger"
    .Body = "Jvf. aftale er her oplysninger" & vbCrLf & "Venlig hilsen Kim"
    .display
    Set xInspect = newEmail.GetInspector
    Set pageEditor = xInspect.WordEditor
    'Sheet1.Range("B2:E5").Copy
    Sheet1.Range("A2").CurrentRegion.Copy
    pageEditor.Application.Selection.Start = Len(.Body)
    pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
    pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
    .display
    '.Send
    Set pageEditor = Nothing
    Set xInspect = Nothing
    End With
    Set newEmail = Nothing
    Set outlook = Nothing
    End Sub

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Help with macro to paste copied tabs in excel directly in mail

    .
    This line of code is referencing "A1" : .To = Sheet1.Range("A1").Text

    What is it you are wanting to change ?

    (You need to place your code in the proper method. Highlight all of your code (in EDIT mode), then click on the # symbol)

  3. #3
    Registered User
    Join Date
    07-27-2020
    Location
    Denmark
    MS-Off Ver
    2019
    Posts
    19

    Re: Help with macro to paste copied tabs in excel directly in mail

    I can't change it, probably because I am a new user - Neither can link to my excel sheet so people can see it themselves

    But issue is

    In A1 is my reference mail I would like to send the copied cells to

    In A2:E5 i have informations that needs to be copied and send in the mail - It is easy to copy those specific cells, but I need a dynamic macro so if I put in more information both in columns or rows and that is my issue

  4. #4
    Registered User
    Join Date
    07-27-2020
    Location
    Denmark
    MS-Off Ver
    2019
    Posts
    19

    Re: Help with macro to paste copied tabs in excel directly in mail

    I have now found a different solution, but now I'm stuck with the issue that no matter what I write in column A it will be copied - Even though I skip a few rows
    - Anyone have a solution to this?

    Please Login or Register  to view this content.

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Help with macro to paste copied tabs in excel directly in mail

    .
    The following will accomplish your goal. You will need to highlight the cell / cells to be included in the body of the email first, then click the SEND button.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] cdo send send mail - getting my external .vbs script directly into a an excel worksheet
    By PieterBlan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2014, 08:10 AM
  2. [SOLVED] I've copied a code directly from YouTube but it doesn't work for me
    By PistachioPedro in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-31-2013, 12:52 AM
  3. [SOLVED] Paste data directly through macro
    By xbr088 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 07-03-2013, 03:43 AM
  4. Excel macro to copy paste a particular range of cells as values in multiple tabs
    By rshnkmr39 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2013, 03:06 PM
  5. [SOLVED] Mail hyperlink turns white / cant paste directly
    By tis1337 in forum Excel General
    Replies: 4
    Last Post: 11-21-2012, 01:02 PM
  6. Macro to copy reports from excel and paste in Outlook Mail
    By dhawalhariyani in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2012, 09:06 AM
  7. Paste Excel Table in Mail using macro
    By vj_sonu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-08-2008, 05:54 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1