Solved

Part 7 to: Import more data into spreadsheet

Posted on 2013-06-13
7
301 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

758 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

21 Experts available now in Live!

Get 1:1 Help Now