Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Part 7 to: Import more data into spreadsheet

Posted on 2013-06-13
7
Medium Priority
?
362 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 31

Accepted Solution

by:
gowflow earned 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

971 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