2017-04-05 44 views
1

我正在接受培訓以編寫將兩個工作表數據暴露組合爲一封電子郵件併發送給其的VBA代碼。 我在下面的代碼中使用了我的調試,但是我沒有做到這一次。 下面的代碼發送一個表的數據和我想從Sheet2的(Worksheets("Sheet2").Range("b3:b30")用於多個範圍的VBA代碼來自多個工作表

Sub Mail_take_2() 

    Dim AWorksheet As Worksheet 
    Dim Sendrng As Range 
    Dim rng As Range 

    On Error GoTo StopMacro 

    With Application 
     .ScreenUpdating = False 
     .EnableEvents = False 
    End With 
    Set Sendrng = Worksheets("Sheet1").Range("c2:j45") 

    Set AWorksheet = ActiveSheet 

    With Sendrng 

     .Parent.Select 

     Set rng = ActiveCell 

     .Select 

     ActiveWorkbook.EnvelopeVisible = True 
     With .Parent.MailEnvelope 

      .Introduction = "This is test mail 2." 

      With .Item 
       .To = "[email protected]" 
       .CC = "" 
       .BCC = "" 
       .Subject = "My subject" 
       .Send 
      End With 

     End With 

     rng.Select 
    End With 

    AWorksheet.Select 

StopMacro: 
    With Application 
     .ScreenUpdating = True 
     .EnableEvents = True 
    End With 
    ActiveWorkbook.EnvelopeVisible = False 

End Sub 

回答

0
 dim myVariable as string 
     dim newRange as string 
     newRange = Range.Value 
     myVariable = myVariable + newRange 

     With .Item 
      .To = "[email protected]" 
      .CC = "" 
      .BCC = "" 
      .Subject = "My subject" 
      .Body = myVariable 
      .Send 
     End With 

它添加額外的怒氣這是否幫助你找出什麼youre意欲何爲?

+0

我很確定它應該是什麼樣子?我嘗試過,沒有發生任何事另外你可以編輯「TO」到「[email protected]」。謝謝。 – Avi22

+0

我如何編輯它到我的代碼? – Avi22

+0

我厭倦了編輯它到我的代碼,但我得到編譯器錯誤。還有什麼想法? – Avi22