PC Review


Reply
Thread Tools Rate Thread

Convert text from clipboard and put in cells...

 
 
Geir Holmavatn
Guest
Posts: n/a
 
      3rd Jan 2007
Hi,

I receive email messages with user data which I need to paste into an
Excel worksheet. If possible I want to copy the data portion of the
email message to the clipboard and have an Excel macro convert it and
paste the different fields into a worksheet.

The text copied into clipboard have this format (fieldname | data
separator is <space>:<space>) :

Forename : John
Family name : Doe
Address : Sunset blvd.
City : San Fransisco

The worksheet columns are as follows:

Name | Address | City

The data from the clipboard should be processed and put into the
worksheet's current row like this:

Doe, John | Sunset blvd. | San Fransisco

Thanks a lot if someone can help us with this

regards

Geir
 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      3rd Jan 2007
Geir,
See if this does what you need. Assumes you have copied from the email and a
Text format is available:

Private Sub CommandButton2_Click()
Dim Clip As DataObject
Dim Info As Variant

On Error GoTo Handler

Const TextFormat As Long = 1
Set Clip = New DataObject

With Clip
.GetFromClipboard
If .GetFormat(TextFormat) = True Then
Info = Split(.GetText(TextFormat), " : ")
Else
MsgBox "No text available"
Exit Sub
End If
End With

With ActiveCell
.Value = Split(Info(2), vbCr)(0) & ", " & Split(Info(1), vbCr)(0)
.Offset(0, 1).Value = Split(Info(3), vbCr)(0)
.Offset(0, 2).Value = Info(4)
End With

Exit Sub
Handler:
MsgBox "Text not in correct structure:" & vbNewLine &
Clip.GetText(TextFormat)
End Sub

There is a recent thread on "microsoft.public.vb.general.discussion",
subject "Something like a Project_Activate event?" which may be useful, if
you wish the improve/extend on the above technique.

NickHK

"Geir Holmavatn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I receive email messages with user data which I need to paste into an
> Excel worksheet. If possible I want to copy the data portion of the
> email message to the clipboard and have an Excel macro convert it and
> paste the different fields into a worksheet.
>
> The text copied into clipboard have this format (fieldname | data
> separator is <space>:<space>) :
>
> Forename : John
> Family name : Doe
> Address : Sunset blvd.
> City : San Fransisco
>
> The worksheet columns are as follows:
>
> Name | Address | City
>
> The data from the clipboard should be processed and put into the
> worksheet's current row like this:
>
> Doe, John | Sunset blvd. | San Fransisco
>
> Thanks a lot if someone can help us with this
>
> regards
>
> Geir



 
Reply With Quote
 
Mike Woodhouse
Guest
Posts: n/a
 
      3rd Jan 2007


On Jan 3, 8:19 am, "NickHK" <TungChe...@Invalid.com> wrote:
> Geir,
> See if this does what you need. Assumes you have copied from the email and a
> Text format is available:
>
> Private Sub CommandButton2_Click()
> Dim Clip As DataObject


The DataObject is accessed by setting a reference in your VBA project
to the Microsoft Forms 2.0 object library. (Use Tools..References)

There's a useful article here:

http://www.cpearson.com/excel/clipboar.htm

HTH,

Mike

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I convert text cells to value nreynol Microsoft Excel Misc 4 14th Dec 2007 08:36 PM
How to convert text to number in cells? =?Utf-8?B?ZXJtZWtv?= Microsoft Excel Programming 4 6th May 2005 08:04 PM
How to convert text-cells Dietmar Brueckmann Microsoft Excel Misc 4 23rd Nov 2004 09:10 AM
Only the text cells with zero convert to numeric =?Utf-8?B?UzRVUkJFIChSb24p?= Microsoft Excel Worksheet Functions 1 23rd Sep 2004 07:11 PM
How can I format text pased directly from clipboard to appear in correct cells pbase Microsoft Excel Programming 1 4th Oct 2003 11:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:18 AM.