S
Sue Mosher [MVP-Outlook]
I can't duplicate the problem here. Since this statement has two objects in it:
TaskDoc.Hyperlinks.Add Anchor:=TaskSel.Range, Address:=FolderHyperlink, _
SubAddress:="", ScreenTip:="", TextToDisplay:=FolderpathText, Target:=""
we can try to get the Range object in a separate statement to see if that's the problem:
Set rng = TaskSel.Range
TaskDoc.Hyperlinks.Add Anchor:=rng, Address:=FolderHyperlink, _
TextToDisplay:=FolderpathText
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
TaskDoc.Hyperlinks.Add Anchor:=TaskSel.Range, Address:=FolderHyperlink, _
SubAddress:="", ScreenTip:="", TextToDisplay:=FolderpathText, Target:=""
we can try to get the Range object in a separate statement to see if that's the problem:
Set rng = TaskSel.Range
TaskDoc.Hyperlinks.Add Anchor:=rng, Address:=FolderHyperlink, _
TextToDisplay:=FolderpathText
--
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 said:Sure. First of all, I got the text of the error backwards. It actually says
that the object referenced has become disconnected from its clients. It
doesn't say which object it is talking about. Here is the code:
'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
.Save
End With
NewTask.ShowCategoriesDialog
NewTask.Display
'Create hyperlink
FolderHyperlink = Replace(FolderpathText, " ", "%20")
Set TaskInsp = NewTask.GetInspector
Set TaskDoc = TaskInsp.WordEditor
Set TaskSel = TaskDoc.Windows(1).Selection
TaskDoc.Hyperlinks.Add Anchor:=TaskSel.Range, Address:=FolderHyperlink, _
SubAddress:="", ScreenTip:="", TextToDisplay:=FolderpathText, Target:=""
'All done
thanks again.
George.
Sue Mosher said:I know nothing about that error and have never seen it. Could you show a little more code so we can try to reproduce the problem? It's necessary to know exactly how you're returning TaskDoc and TaskSel and where you've put NewTask.DIsplay.
showme1946 said:Hi, Sue -
Yes, TaskSel and TAskDoc show as valid objects in the locals window.
However, the error has changed.
I relocated the NewTask.Display statement and got rid of the early binding
error. Now, this statement:
TaskDoc.Hyperlinks.Add Anchor:=TaskSel.Range, Address:=FolderHyperlink, _
SubAddress:="", ScreenTip:="", TextToDisplay:=FolderpathText, Target:=""
Produces the following error: -2147417848; the text associated with this
error states that the client has become disconnected from its object. Also,
I have to reboot my computer, as it appears that memory gets assigned that is
not released and a bunch of things quit working (like, nothing happens when I
right-click on something). When I look up this error in the KB, I find
articles describing similar errors in Excel VB and statements that it is a
bug. But those articles reference older versions, so I am unclear about
whether those articles are pertinent to what I am experiencing with Outlook
2007.
Thanks for your help.
George.
:
If you look in the Locals window, do TaskSel and TaskDoc show as valid objects?
Hi, Sue
Oh, I guess I thoughe Dim obj as object was declaring them. The statement
that gets the error is:
TaskDoc.Hyperlinks.Add Anchor:=TaskSel.Range, Address:=FolderHyperlink,
TexttoDisplay:=FolderpathText
:
Which statement raises the error?
Hi, Sue -
Thanks so much for your reply. I tried adding the reference, as I had not
done that; it did not fix the problem. I got your book, which is excellent
by the way, and it was very helpful, especially in confirming and clarifying
what you've said in this thread. However, using the code you suggested still
does not work. I get an error, with a long number preceded by a "-".
:
What do you mean by "won't recognize"? Did you add a reference to the Microsoft Word library to your project?
Hi, Sue -
[I've ordered your book, by the way] but until it comes I hope you can
help me further with this project. I have been trying the method you
describe below, but Outlook 2007 won't recognize the elements from the Word
object model. I assume there is something I need to do, but I havenot been
able to figure out what that is.
My code is:
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 TaskInsp As Object
Dim TaskDoc As Object
Dim TaskSel As Object
Dim TaskSubj As String
Dim TaskDue As Date
Dim TaskCategory As String
Dim FolderpathText As String
Dim FolderHyperlink As String
'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
'Create hyperlink
FolderHyperlink = Replace(FolderpathText, " ", "%20")
Set TaskInsp = NewTask.GetInspector
Set TaskDoc = TaskInsp.WordEditor
Set TaskSel = TaskDoc.Windows(1).Selection
TaskDoc.Hyperlinks.Add Anchor:=TaskSel.Range, Address:=FolderHyperlink,
TexttoDisplay:=FolderpathText
NewTask.Display
'All done
:
Outlook 2007 uses Word as the email editor for all items. Therefore, you can use the Document.Hyperlinks.Add method from the Word object model to insert a link in the body of a task, something along these lines:
strLink = Replace("outlook://Mailbox - Rickerson, George/Tasks/Testfolder", " ", "%20")
strLinkText = "George's mailbox"
Set objInsp = NewTask.GetInspector
Set objDoc = objInsp.WordEditor
Set objSel - objDoc.Windows(1).Selection
objDoc.Hyperlinks.Add objSel.Range, strLink, _
"", "", strLinkText, ""
Pardon me for not noting earlier that I am using OL2007. I need a
way to accomplish this in OL07.