Solved

Part 7 to: Import more data into spreadsheet

Posted on 2013-06-13
7
351 Views
Last Modified: 2013-06-14
This is a continuation from: http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28156423.html

Gowflow, if the below is too much for one question, let me know and I'll break it up.

When I put a value in Col N (Funds Rcvd) AND there is already a value in Col K (USD MC) THEN do the following:

1. Open up an email and address it to: nmai@banking.bz, with a bcc going to: david@offshorelawcenter.com

2. Subject: New Mastercard Application for (here insert first and last name from Col B and C)

3. Body (without quotes):

"Hi Nalleli,

Attached are the documents and load request for  (here insert first and last name from Col B and C)

Please have his card shipped to address indicated on spreadsheet.

PIC:99554Freedom

Please let me know you received this email.

Thank you.

Michael
Sovereign Gold Card Support
www.sovereigngoldcard.com"

4. Attach the files inserted into Applicant Status from all cells (Col E - H), even if it has as many as 5 or 6 (or more) different files on two (or more) different rows

That's it for now. This function will do a bit more later, once this one works.

Thank you!
0
Comment
Question by:JaseSt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 31

Accepted Solution

by:
gowflow earned 500 total points
ID: 39247963
here it is

1) Make a copy of your latest file and give it a new name
2) goto VBA and right click on the name of the project in the left pane and choose Insert/Module
3) Module1 will be created doubleclick on it and copy/paste the below code there

Sub SendEmail(Rng As Range)
Dim wb As Workbook
Dim WS As Worksheet


Dim SendTo As String
Dim Blindcc As String
Dim OutlookApp As Object
Dim MItem As Object
Dim subject_ As String
Dim attach_ As String
Dim fFile
Dim omail As Outlook.MailItem

Application.DisplayAlerts = False

'Create Outlook
Set OutlookApp = CreateObject("Outlook.Application")

'Fill in Subject Details'
subject_ = "New Mastercard Application for (" & Rng.Cells(1, "B") & " " & Rng.Cells(1, "C") & ")"
SendTo = "nmai@banking.bz"
Blindcc = "david@offshorelawcenter.com"

'Create the Email
Set MItem = OutlookApp.CreateItem(0)
With MItem
  .To = SendTo
  .BCC = Blindcc
  .Subject = subject_
  
  '---> Attach files
  For Each fFile In Rng.SpecialCells(xlCellTypeFormulas)
        If InStr(1, fFile.Formula, "HYPERLINK") <> 0 Then
            fpos = InStr(1, fFile.Formula, "HYPERLINK") + 11
            attach_ = Mid(fFile.Formula, fpos, InStr(fpos, fFile.Formula, Chr(34)) - fpos)
            .Attachments.Add (attach_)
        End If
  Next fFile
  
  .Body = "Hi Nalleli," & Chr(10) & Chr(10) _
    & "Attached are the documents and load request for (" & Rng.Cells(1, "B") & " " & Rng.Cells(1, "C") & ")" & Chr(10) _
    & "Please have his card shipped to address indicated on spreadsheet." & Chr(10) _
    & "PIC:99554Freedom" & Chr(10) & Chr(10) _
    & "Please let me know you received this email." & Chr(10) & Chr(10) _
    & "Thank you." & Chr(10) & Chr(10) _
    & "Michael" & Chr(10) _
    & "Sovereign Gold Card Support" & Chr(10) _
    & "www.sovereigngoldcard.com"

  'Send the Email
  .Display
End With

'Clear Resources
Set MItem = Nothing
Set OutlookApp = Nothing

Application.DisplayAlerts = True
End Sub

Open in new window


4) SAVE the workbook
5) doubleclick on Sheet1 in the left pane and choose to view 1 sub at a time by clicking on the bottom left icon
6) Select Worksheet change event and delete the code that is between Private Sub and End Sub
Private Sub Worksheet_Change(ByVal Target As Range)

< delete all the code that is between these 2 lines >

End Sub

7) Insert the below code after
Private Sub Worksheet_Change(ByVal Target As Range)

Dim cCell As Range

For Each cCell In Target
    If (Not Intersect(cCell, Columns("O")) Is Nothing Or _
        Not Intersect(cCell, Columns("P")) Is Nothing Or _
        Not Intersect(cCell, Columns("Q")) Is Nothing Or _
        Not Intersect(cCell, Columns("R")) Is Nothing Or _
        Not Intersect(cCell, Columns("S")) Is Nothing) _
        And LCase(cCell.Value) = "x" Then
        cCell = Format(Now, "mm/dd/yyyy")
    End If
Next cCell

'---> Send Email if Cell in Col N has a value and Cell in Col K
If Not Intersect(Target, Columns("N")) Is Nothing And _
    Not Range("K" & Target.Row) Is Nothing Then
    If MsgBox("Send Mail for " & Cells(Target.Row, "C") & ", " & Cells(Target.Row, "B") & " ?", vbQuestion + vbYesNo, "Send Email") = vbYes Then
        SendEmail Range(Cells(Target.Row, "A"), Cells(Target.Row, "T"))
    End If
End If

Open in new window


8) SAVE and Exit the workbook
9) Open it and take any row and add value in Col K then add value in Col N and see the results.

gowflow
0
 

Author Comment

by:JaseSt
ID: 39248035
works beautifully, but it also pops up the email notification when I put a value in N and there is NO value in Col K.

In other words, just putting a value in K starts the macro.  

I need to have a value in Col K before it kicks off because in another addition to this code (future question) the email message and recipient will be different if there is a value in Col J and a value in K

Also, deleting a value in N pops up the email macro.
0
 

Author Comment

by:JaseSt
ID: 39248041
"In other words, just putting a value in K starts the macro. "

I meant: In other words, just putting a value in N starts the macro.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 31

Expert Comment

by:gowflow
ID: 39248104
ok sorry my mistake

replace these 2 lines in Workbbok_Change event of sheet 1

If Not Intersect(Target, Columns("N")) Is Nothing And _
    Not Range("K" & Target.Row) Is Nothing Then

Open in new window


by these 2 lines

If Range("N" & Target.Row) <> "" And _
    Range("K" & Target.Row) <> "" Then

Open in new window


gowflow
0
 

Author Closing Comment

by:JaseSt
ID: 39248256
Perfect!

Now need to do something else, if you're open.
0
 
LVL 31

Expert Comment

by:gowflow
ID: 39248300
Shoot
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question