Solved

Part 7 to: Import more data into spreadsheet

Posted on 2013-06-13
7
313 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
  • 4
  • 3
7 Comments
 
LVL 29

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 29

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 29

Expert Comment

by:gowflow
ID: 39248300
Shoot
0
 

Author Comment

by:JaseSt
ID: 39248384
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now