Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Lookup Mail Contact

I use a spreadsheet with a macro attached to import a text
file "file.*" the file is then formatted and sent to a
mail recipient via outlook. This works really cleanly, but
I now wish to make the mail recipient dependant on a value
held within the text file. My problem is that the text
file is opened from the sheet A063 the processing
completed and the file is then dumped. The cell with the
contact reference number is held in cell d21 on the active
sheet but the lookup is held on the sheet A063. Is it
possible to use a lookup to set a string contact name from
the same macro that formats the text file? If so how?
Any help appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 340
Default Lookup Mail Contact

Jill, yes you can. You would need to do something like this:

Set rangeToSearch = Workbooks("name_of_wb_containing_AO63.xls") _
.Sheets("AO63").Range("email_lookup_and_address_ra nge")

foundValue = Application.VLookup(range("d21"), _
rangeToSearch, 2, False)
If IsError(foundValue) Then
MsgBox "No match found"
'code to stop macro
End If

'code to use foundValue as the email address

Robert Flanagan
Macro Systems
Delaware, U.S. 302-234-9857
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


"Jill" wrote in message
...
I use a spreadsheet with a macro attached to import a text
file "file.*" the file is then formatted and sent to a
mail recipient via outlook. This works really cleanly, but
I now wish to make the mail recipient dependant on a value
held within the text file. My problem is that the text
file is opened from the sheet A063 the processing
completed and the file is then dumped. The cell with the
contact reference number is held in cell d21 on the active
sheet but the lookup is held on the sheet A063. Is it
possible to use a lookup to set a string contact name from
the same macro that formats the text file? If so how?
Any help appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Lookup Mail Contact

Thanks for your response, I am not quite sure of the
correct references to place in the places you have
indicated. For 1. the workbook that contains both the
macro and the email lookup address range is
named 'A063inv.xls' I believe that this should go in
position A between the quotes!. For 2. the address range
is held in 'invA063!sheet1!a1:b20 the A column holds the
refernce that is found in the active workbook that is
being processed (the text file which can be named File.004
or File.007 and is opened by looking for the
file "File.*") column B holds the e-mail recipients name.
For 3. the reference is held on File.*!D21.

1. Set rangeToSearch = Workbooks("A") _
2. .Sheets("B").Range("C")

3. foundValue = Application.VLookup(range("D"), _
rangeToSearch, 2, False)
If IsError(foundValue) Then
MsgBox "No match found"
'code to stop macro
End If

I completed the code with the following;

A = A063inv
B = sheet1
C= A1:B20
D= D21

The code fails with 'Subscript out of range' on the first
section. Would you please have a look at this and correct
my references.
Thanks
Jill

-----Original Message-----
Jill, yes you can. You would need to do something like

this:

Set rangeToSearch = Workbooks

("name_of_wb_containing_AO63.xls") _
.Sheets("AO63").Range

("email_lookup_and_address_range")

foundValue = Application.VLookup(range("d21"), _
rangeToSearch, 2, False)
If IsError(foundValue) Then
MsgBox "No match found"
'code to stop macro
End If

'code to use foundValue as the email address

Robert Flanagan
Macro Systems
Delaware, U.S. 302-234-9857
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros

for Excel


"Jill" wrote in

message
...
I use a spreadsheet with a macro attached to import a

text
file "file.*" the file is then formatted and sent to a
mail recipient via outlook. This works really cleanly,

but
I now wish to make the mail recipient dependant on a

value
held within the text file. My problem is that the text
file is opened from the sheet A063 the processing
completed and the file is then dumped. The cell with the
contact reference number is held in cell d21 on the

active
sheet but the lookup is held on the sheet A063. Is it
possible to use a lookup to set a string contact name

from
the same macro that formats the text file? If so how?
Any help appreciated.



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
mail merge multiple lines in an e-mail Guy[_2_] Excel Discussion (Misc queries) 1 December 1st 09 08:32 PM
How do I do an e-mail mail merge using an Excel spreadsheet? Gretchen Excel Worksheet Functions 0 July 19th 09 05:18 PM
Error: cannot load the mail service. Check your mail installation. Brad Bowser Excel Discussion (Misc queries) 0 December 20th 05 10:03 PM
General mail failure when sending e-mail from Excel Adrienne Excel Discussion (Misc queries) 5 November 4th 05 12:59 PM
contact scottwilsonx[_22_] Excel Programming 1 August 11th 04 06:18 PM


All times are GMT +1. The time now is 08:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"