A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Use VBA to insert hyperlink in Task Body



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #26  
Old October 8th 07, 07:21 PM posted to microsoft.public.outlook.program_vba
showme1946
external usenet poster
 
Posts: 15
Default Use VBA to insert hyperlink in Task Body

Hi, Sue -
One more thing: your first observation below is not actually correct. It
is not necessary to replace the spaces in the path of the folder with %20. I
am simply using the path of the folder as returned by Outlook as the address,
and it works fine - just like in your book!!

Thanks,
George.

"Sue Mosher [MVP-Outlook]" wrote:

Your inserted links aren't working because you're using FolderpathText instead of FolderpathHyperlink for the Address parameter in your Hyperlinks.Add statement.

As for the error, this is too weird: Running your code, I saw the error you described just a couple of times, but every other time, I got an out-of-memory or disk space error. The main difference between your code and my test code, which worked fine 100% of the time, is that I was lazy and didn't declare all my variables, only Tasks. When I commented all your Dim statements except Dim Tasks, your code worked fine. So I worked my way back through all the Dim statements and found the surprising culprit:

Dim FolderpathText As String

Commenting out that statement made your code work without error every time. It also worked with just Dim FolderpathText without the As String modifer. I can't explain it. Try it and see if it works for you.

You also don't need this statement:

.Body = FolderpathText

because the text is inserted by the Hyperlinks.Add statement.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"showme1946" wrote in message ...
Hi, Sue -
The suggestion to isolate the range object did not work - the same error
was thrown when the hyperlink.add statement is executed.

Some additional info that might help: the task is created, and the body
of the task does contain the folderhyperlink string, and the string looks
like a hyperlink, i.e., it is blue and underlined. However, the body of the
task is inert - that is, one cannot edit it or do anything to it. One cannot
type in it, one gets no response to clicking on the hyperlink string or
right-clicking the string. Again however, if one selects "hyperlink" from
the ribbon, the hyperlink information appears in the hyperlink dialog box and
looks completely normal. Obviously the error prevents completion of some
process that makes the body of the text editable or actionable.

I am going to experiment with the hyperlink.add method in MS Word to see
if the same error is thrown there.

By the way, here is my complete code - I just can't believe you don't get
the same error, and I'm hoping you see something in the declarations or
somewhere that pertains to this: (in this code the hyperlink.add statement is
commented out)

Sub Main()
On Error GoTo TaskFolderCreate_err
'Declare variables
Dim ns As NameSpace
Dim Tasks As Folder
Dim NewTask As TaskItem
Dim NewFolder As Folder
Dim TaskSubj As String
Dim TaskDue As Date
Dim FolderpathText As String
' Dim FolderHyperlink As String
Dim TaskInsp As Object
Dim TaskDoc As Object
Dim TaskSel As Object
Dim TaskWindow As Object
Dim TaskRange As Object
'Initialize variables
Set ns = GetNamespace("MAPI")
Set Tasks = ns.GetDefaultFolder(olFolderTasks)
TaskSubj = ""
FolderpathText = ""
' FolderHyperlink = ""
TaskDue = Now
'Get Name and Due Date Of Task and Folder
TaskSubj = InputBox(Prompt:="Enter Subject for Task and Folder:",
Title:="ENTER SUBJECT", Default:="")
If TaskSubj = "" Then GoTo TaskFolderCreate_err
TaskDue = InputBox(Prompt:="Enter Due Date for Task:", Title:="ENTER DUE
DATE", Default:=Now)
'Create folder
Set NewFolder = Tasks.Folders.Add(TaskSubj, olFolderInbox)
FolderpathText = NewFolder.Application & ":" & NewFolder.Folderpath
'Create task
Set NewTask = CreateItem(olTaskItem)
With NewTask
.Subject = TaskSubj
.DueDate = TaskDue
.Body = FolderpathText
.Save
End With
NewTask.ShowCategoriesDialog
NewTask.Display
'Create hyperlink
' FolderHyperlink = Replace(FolderpathText, " ", "%20")
Set TaskInsp = NewTask.GetInspector
Set TaskDoc = TaskInsp.WordEditor
Set TaskWindow = TaskDoc.Windows(1)
Set TaskSel = TaskWindow.Selection
Set TaskRange = TaskSel.Range
' TaskDoc.Hyperlinks.Add Anchor:=TaskRange, Address:=FolderpathText, _
' SubAddress:="", ScreenTip:="", TextToDisplay:=FolderpathText, Target:=""
'All done
TaskFolderCreate_exit:
Set ns = Nothing
Set Tasks = Nothing
Set NewFolder = Nothing
Set NewTask = Nothing
Set TaskInsp = Nothing
Set TaskDoc = Nothing
Set TaskSel = Nothing
Set TaskRange = Nothing
Exit Sub
TaskFolderCreate_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: eMailtoTask" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume TaskFolderCreate_exit
End Sub


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
insert hyperlink me Outlook - General Queries 1 May 4th 07 03:42 PM
Save Attachment and insert hyperlink Ozgur Pars Outlook and VBA 1 February 5th 07 04:49 PM
insert as text (to insert html into email body) Iona Outlook - General Queries 1 July 13th 06 12:10 PM
vba code that insert a hyperlink file in the body of message gabriel Outlook and VBA 3 April 24th 06 01:51 PM
Insert a hyperlink to section of Word doc in an outlook message [email protected] Outlook - General Queries 0 February 8th 06 05:07 AM


All times are GMT +1. The time now is 11:10 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.