Solved

click email address hyperlink and attached open excel file

Posted on 2014-01-06
6
2,635 Views
Last Modified: 2014-01-13
Hi Experts using excel 2007

is it possible when you click a hyperlink of a persons name, which is the email address to at the same time attach a copy of the open and current excel file to the email...you are about to send.
0
Comment
Question by:route217
  • 4
  • 2
6 Comments
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39759279
Is the hyperlink in an excel worksheet?

If so you can use the following worksheet function:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
End Sub

Open in new window

0
 

Author Comment

by:route217
ID: 39759320
Excellent feedback let me test...

and yes it is an excel 2007 workbook...
0
 

Author Comment

by:route217
ID: 39759560
Hi buttersk

just tried vba in the worksheet function and its not adding an workbook attachment...
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 19

Accepted Solution

by:
Ken Butters earned 500 total points
ID: 39759851
ok... let me expand on this...

The followhyperlink will execute after you have clicked on the link.  you will now have two simultaneous processes working.  Your spreadsheet and outlook.

So here is an overview of the order of events :

1) you click on the hyperlink
2) Outlook is opened an an email is created
3) the worksheet_FollowHyperlink function is called if it exists

When the worksheet_followhyperlink function is called, we need to add some specific code to the worksheet_followHyperlink function to add an attachment to the email.

To get at the Microsoft outlook library functions you should add a reference to :
Microsoft Outlook xx.x Object Library  xx.x will change depending upon your version of outlook.

In VB Editor go to tools / References and look for Microsoft outlook 12.0 object library or whatever the latest number you have available.

Then in the VBE project pane, select the worksheet that has the hyperlink

Add the following code to that worksheet.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

    Dim newAttachment As attachment
    Dim mail As MailItem
    Dim olApp As Outlook.Application
    Dim inspectorObj As Inspector
    Dim TimeOutCounter As Integer
    
    
    Set olApp = New Outlook.Application
    Set inspectorObj = olApp.ActiveWindow
    
    '  May need to wait until outlook has opened and started email message
    '   --- also need a way to time-out in case outlook doesn't open the email
    
    TimeOutCounter = 0
    Do
        If inspectorObj.CurrentItem.Class = olMail Then: Exit Do
        Sleep 1000
        DoEvents
        TimeOutCounter = TimeOutCounter + 1
        If TimeOutCounter > 5 Then: Exit Do
    Loop
    
    If inspectorObj.CurrentItem.Class <> olMail Then: Exit Sub
    
    Set mail = inspectorObj.CurrentItem
    
    Set newAttachment = mail.Attachments.Add(ThisWorkbook.FullName, olByReference, , ThisWorkbook.FullName)
    newAttachment.DisplayName = ThisWorkbook.FullName

End Sub

Open in new window


Now when you click on the hyperlink, the current book should be added as an attachment to the email.

you should note that the workbook being attached is the version that was last saved.  So if you made changes you want emailed... you would have to save the workbook first.

you could do this by adding something like "thisworkbook.save" prior to adding it as an attachment.
0
 

Author Comment

by:route217
ID: 39759853
Hi bittersk

any thought on the worksheet function....
0
 

Author Comment

by:route217
ID: 39759859
Excellent ignore my previous email..buttersk
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
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.

746 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

10 Experts available now in Live!

Get 1:1 Help Now