Login | |
|
 |
RE: Creating hyperlinks in a Word doc with VBS - 2/28/2008 12:42:45 AM
|
|
 |
|
| |
Thorsteenster
Posts: 18
Score: 0
Joined: 2/27/2008
Status: offline
|
I found this at http://www.mcfedries.com/ABGVBA/Chapter12.doc Object.Hyperlinks.Add(Anchor, Address, SubAddress, ScreenTip, TextToDisplay, Target) Object The object in which you want to insert the hyperlink (such as a Document or Range object in Word, or a Worksheet or Range object in Excel). Anchor The object the user will click to follow the hyperlink. This could be a section of text, a Range object, or a graphic. Address The address of the link, which can be a file path, a UNC path, or a URL. Remaining parameters are optional. Then this at MSDN http://msdn2.microsoft.com/en-us/library/aa221980(office.11).aspx These are the two best examples I've found. Thanks!
< Message edited by Thorsteenster -- 2/28/2008 12:46:58 AM >
|
|
| |
|
|
|
 |
RE: Creating hyperlinks in a Word doc with VBS - 2/28/2008 1:35:35 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
Let me be more explicit. Post code that you have actually tried to convert along with the converted VBS code and a good explaination of how it did not work.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Creating hyperlinks in a Word doc with VBS - 2/28/2008 1:54:03 AM
|
|
 |
|
| |
Thorsteenster
Posts: 18
Score: 0
Joined: 2/27/2008
Status: offline
|
The VBS code was a Hey SCripting Guy article on MS, it was for a very basic sig. I added color, so really I havn't converted any syntax, just expanded on what I had. The hyperlink line dosn't return anything unless I have it in an improper format, an illegal character and leaving it open to something expected, then it just pops up with an error. It's looking like I need to set something as an anchor for the HL and do something like hyperlinks.add(anchor, www.url.com) I'm going to play with creating a variable, have it typetext the variable and set the variable name as the anchor. If your interested, here is what I have so far, it pulls info out of AD and inserts into a Word doc and saves it as a sig and sets it as default sig in Outlook. On Error Resume Next Set objSysInfo = CreateObject("ADSystemInfo") strUser = objSysInfo.UserName Set objUser = GetObject("LDAP://" & strUser) strName = objUser.FullName strTitle = objUser.Title strDepartment = objUser.Department strCompany = objUser.Company strPhone = objUser.telephoneNumber Set objWord = CreateObject("Word.Application") Set objDoc = objWord.Documents.Add() Set objSelection = objWord.Selection Set objEmailOptions = objWord.EmailOptions Set objSignatureObject = objEmailOptions.EmailSignature Set objSignatureEntries = objSignatureObject.EmailSignatureEntries objselection.font.name = "arial" objselection.font.size = "11" objselection.font.bold = true objselection.font.color = RGB(80, 0, 217) objSelection.TypeText1 strName objselection.font.color = RGB(255, 92, 0) objselection.TypeText2 " | " objselection.font.color = RGB(80, 0, 217) objselection.TypeText3 strTitle objselection.font.color = RGB(255, 92, 0) objselection.TypeText4 " | " objselection.font.color = RGB(80, 0, 217) objselection.TypeText5 strPhone objSelection.TypeParagraph() objSelection.TypeText6 strCompany objselection.font.color = RGB(255, 92, 0) objselection.TypeText7 " | " objselection.font.color = RGB(80, 0, 217) objselection.TypeText8 strDepartment objSelection.TypeParagraph() objSelection.TypeParagraph() objselection.font.color = RGB(0, 0, 128) objselection.typetext9 "Interested in building a playground or in the process of planning? You’re not alone! Kaboom.org has hundreds of playground project postings from people just like you, who used the KaBOOM! Project Planner to make their playground dream a reality." objselection.font.color = RGB(80, 0, 217) objselection.typetext10 " How did a community solve fundraising issues? Or collect tools? Or round up volunteers? You can find their answers and experiences at http://projects.kaboom.org/!" Set objSelection = objDoc.Range() objSignatureEntries.Add "KaBOOM! Sig", objSelection objSignatureObject.NewMessageSignature = "KaBOOM! Sig" objSignatureObject.ReplyMessageSignature = "KaBOOM! Sig" objDoc.Saved = True objWord.Quit
|
|
| |
|
|
|
 |
RE: Creating hyperlinks in a Word doc with VBS - 2/28/2008 1:58:05 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
I didn't even read past the first line of your code. Remove the global On Error Resume Next. Especially while you are doing your development.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Creating hyperlinks in a Word doc with VBS - 2/28/2008 2:05:47 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
Is this all of your code? I can't think that it is. There are a lot of objects in the code that are never created. Where are they coming from?
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Creating hyperlinks in a Word doc with VBS - 2/28/2008 2:47:57 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
To actually use the macro itself you would need to run it in Word. The real use of the macro recorder for a scripter is to record a macro doing what you want then look at the generated code and convert it over to VBS.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Creating hyperlinks in a Word doc with VBS - 3/20/2008 2:07:08 AM
|
|
 |
|
| |
Thorsteenster
Posts: 18
Score: 0
Joined: 2/27/2008
Status: offline
|
Whew, ok, I got sidetracked but now am back to this project. Here is the code I got from recording a macro: Selection.TypeText Text:="www.linkhere.com" Selection.MoveLeft Unit:=wdCharacter, Count:=16, Extend:=wdExtend ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _ "www.linkhere.com", SubAddress:="", ScreenTip:="", TextToDisplay:= _ "www.linkhere.com" I have tried pasting it into the script, changing selection to objselection to match the rest of the script, and a couple of other things. I think it might be something with VBS not understanding, or not the right format, the Activedocument.Hyperlinks.Add statement. I got a couple of other thoughts I'll try.
|
|
| |
|
|
|
 |
RE: Creating hyperlinks in a Word doc with VBS - 3/20/2008 2:42:37 AM
|
|
 |
|
| |
Thorsteenster
Posts: 18
Score: 0
Joined: 2/27/2008
Status: offline
|
here is the whole script, in the next post I'll post a couple variations and the different error messages. Set objSysInfo = CreateObject("ADSystemInfo") strUser = objSysInfo.UserName Set objUser = GetObject("LDAP://" & strUser) strName = objUser.FullName strTitle = objUser.Title strDepartment = objUser.Department strCompany = objUser.Company strPhone = objUser.telephoneNumber Set objWord = CreateObject("Word.Application") Set objDoc = objWord.Documents.Add() Set objSelection = objWord.Selection Set objEmailOptions = objWord.EmailOptions Set objSignatureObject = objEmailOptions.EmailSignature Set objSignatureEntries = objSignatureObject.EmailSignatureEntries objselection.font.name = "arial" objselection.font.size = "11" objSelection.TypeText strName objSelection.TypeParagraph() objselection.TypeText strTitle objSelection.TypeParagraph() objselection.TypeText strCompany objSelection.TypeParagraph() objSelection.TypeText strDepartment objSelection.TypeParagraph() objselection.TypeText strPhone objSelection.TypeParagraph() objSelection.TypeParagraph() objselection.font.bold = true objselection.typetext "Interested in building a playground or in the process of planning? You're not alone! Kaboom.org has hundreds of playground project postings from people just like you, who used the KaBOOM! Project Planner to make their playground dream a reality." objselection.typetext " How did a community solve fundraising issues? Or collect tools? Or round up volunteers? You can find their answers and experiences at " objselection.font.underline = true objselection.font.color = RGB(0, 0, 255) objselection.typetext "http://projects.kaboom.org/" objselection.font.underline = false objselection.font.color = RGB(0, 0, 0) objselection.typetext "!" Set ActiveDocument = objdoc.range() ActiveDocument.Hyperlinks.Add Anchor = ObjSelection.Range, Address = _ "http://kaboom.org", SubAddress = "", ScreenTip = "", TextToDisplay = _ "http://kaboom.org" Set objSelection = objDoc.Range() objSignatureEntries.Add "KaBOOM! Sig", objSelection objSignatureObject.NewMessageSignature = "KaBOOM! Sig" objSignatureObject.ReplyMessageSignature = "KaBOOM! Sig" objDoc.Saved = True objWord.Quit Returns this error: Line: 47 Char: 1 Error: Type Mismatch: 'ActiveDocument.Hyperlinks.Add" Code: 800A000D Line 47, Char 1 is the ActiveDocument.Hyperlinks.Add statement. Also, with this one here, I tried setting ActiveDocument to ObjDoc.range
< Message edited by Thorsteenster -- 3/20/2008 2:44:00 AM >
|
|
| |
|
|
|
|
|