MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 17th, 2002, 03:11 PM   #1
bobmc
Board Regular
 
Join Date: Mar 2002
Posts: 142
Default

I have an online form, the results of which are submitted as email to the recipient. The email that shows up to the recipient looks like this:

Name: Joe Smith
Address: 123 Cherry Lane
City: Los Angeles
Submit: Submit

Here's my question. How do I import this text into Excel so the field names ("Name", "Address", etc.) show up in, say, column A and the field entries ("Joe Smith", "123 Cherry Lane", etc.) show up in column B?

I am successful in this endeavor if I copy the email text, paste it into notepad (or any other text editor), save it as a .txt file, then import to Excel, indicating a colon as the delimiter. Is there a more direct way to do this?

Any help is greatly appreciated!
bobmc is offline   Reply With Quote
Old Apr 17th, 2002, 03:54 PM   #2
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

I was hoping someone else would post, because I'm a little embarassed of my following code. I assume there is a lot easier to import an email to excel (but hey, I don't know how to do it). So you can try the following code (no laughing at my procedure).
Code:
Public Const SW_RESTORE As Long = 9&
Public Const GW_CHILD As Long = 5&
Public Const GW_HWNDNEXT As Long = 2&

Declare Function GetDesktopWindow& Lib "user32" ()
Declare Function GetWindow& Lib "user32" (ByVal hWnd&, ByVal wCmd&)
Public Declare Function GetWindowText& Lib "user32" Alias "GetWindowTextA" _
(ByVal hWnd&, ByVal lpString$, ByVal cch&)
Declare Function ShowWindow& Lib "user32" (ByVal hWnd&, ByVal nCmdShow&)
Public Declare Function SetForegroundWindow& Lib "user32" (ByVal hWnd&)
Sub Main()
Const BaseCaption As String = " - Message"
Dim AppWindow&, sTemp$, StartTime, CycleTime

StartTime = Now
AppWindow = GetWindow(GetDesktopWindow(), GW_CHILD)
Do While CycleTime - StartTime < TimeValue("00:00:01")
sTemp = String$(180, False)
Call GetWindowText(AppWindow, sTemp, 179)
If InStr(sTemp, BaseCaption) Then
ActivateWindow AppWindow
Exit Sub
End If
AppWindow = GetWindow(AppWindow, GW_HWNDNEXT)
CycleTime = Now
Loop
MsgBox "The window is not open"
End Sub
Private Sub ActivateWindow(ByVal AppWindow&)
Call ShowWindow(AppWindow, SW_RESTORE)
Call SetForegroundWindow(AppWindow)
End Sub
Sub ExtractEmail()
Call Main
SendKeys "%(E)", True
SendKeys "L", True
SendKeys "%(E)", True
SendKeys "C", True
AppActivate "Microsoft Excel"
Workbooks("Book2.xls").Activate
Worksheets("Sheet1").Select
Range("a1").Select
ActiveSheet.Paste
Columns("A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
    :=":", FieldInfo:=Array(1, 1)

End Sub
Run ExtractEmail
Change Const BaseCaption As String = " - Message"
So that " - Message" is a text string that appears in the window ID. I chose " - Message" because I am using Outlook and it is in every email's window ID.
__________________
Kind regards,

Al Chara
Al Chara is offline   Reply With Quote
Old Apr 18th, 2002, 12:50 AM   #3
bobmc
Board Regular
 
Join Date: Mar 2002
Posts: 142
Default

Thanks for the reply, Al...

Two quick questions about this code.

1. Where exactly should I place it? Does it go in one of the sheets, or does it go in "This Workbook"?

2. What do you mean by "Run" ExtractEmail?

(I know basically nothing about VB code.)

Thanks!
bobmc is offline   Reply With Quote
Old Apr 18th, 2002, 07:44 AM   #4
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Quote:
On 2002-04-17 23:50, bobmc wrote:
Two quick questions about this code.

1. Where exactly should I place it? Does it go in one of the sheets, or does it go in "This Workbook"?

----It goes in a standard module

2. What do you mean by "Run" ExtractEmail?

----The macro that makes it all happen is ExtractEmail. So when you want to extract an email, make sure the email is open and then run the ExtractEmail macro (Alt+F8, in excel).

_________________
Hope this helps.
Kind regards, Al.

[ This Message was edited by: Al Chara on 2002-04-18 06:45 ]
Al Chara is offline   Reply With Quote
Old Apr 18th, 2002, 11:34 AM   #5
bobmc
Board Regular
 
Join Date: Mar 2002
Posts: 142
Default

OK...

I see how the "run" function works now. Once I ran it I got some errors...might be because I'm a little confused about the "Window ID" you speak of. Is that the very top app window heading, i.e.(I also use Outlook and mine says "Inbox - Microsoft Outlook".)

Please advise. And thanks for the help!
bobmc is offline   Reply With Quote
Old Apr 18th, 2002, 12:46 PM   #6
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Yes, for Outlook it would say "Inbox - Microsoft Outlook". But my code looks for open messages. Since I do not know exactly what the window ID will be, I used a search string " - Message" That string appears in the Window ID of every Outlook Message, ie Message Subject "- Message"

Since you are using Outlook, do not change my code at all. It should run for you.
__________________
Kind regards,

Al Chara
Al Chara is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 10:15 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes