#197781 - 2010-02-15 11:57 AM
How to get this from VBS to KiXtart
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
I'm playing a bit with pictures in our outlook signature script so we can include some small icons for our company facebook, youtube channel, blog and twitter pages. There is an option to give a picture a hyperlink so it becomes clickable. I did this in Word and recorded a macro of it (see below). Small issue........I have no idea how to get the script that sets the hyperlink to work in KiXtart. Inserting the picture works fine. Sure I can just insert some text as a hyperlink but it looks much cleaner when it is just the icons and no text.
Selection.InlineShapes.AddPicture FileName:= _
"S:\Facebook.gif", LinkToFile:=False, _
SaveWithDocument:=True
ActiveDocument.DefaultTargetFrame = ""
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
"http://www.test.com/", SubAddress:="", ScreenTip:="Some tooltip text here" _
, TextToDisplay:=""
VBS code from this website:
'Insert a picture.
Set oILPic = oDoc.InlineShapes.AddPicture(Range:=oDoc.Content, FileName:= sPicFile, LinkToFile:=True)
'Add a hyperlink For the picture.
oDoc.Hyperlinks.Add Anchor:=oILPic.Range, Address:=sLinkFile
'Use the InlineShapes Property To reference the Object.
Set oHLink = oDoc.InlineShapes(1).Hyperlink
Edited by Mart (2010-02-15 05:14 PM) Edit Reason: Added vbs code
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
|
Top
|
|
|
|
#197845 - 2010-02-23 09:27 AM
Re: How to get this from VBS to KiXtart
[Re: Glenn Barnas]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Try this:
$objDoc.Hyperlinks.Add("Anchor:="+$objShape.Range, "Address:=http://www.someurl.com")
|
|
Top
|
|
|
|
#197857 - 2010-02-24 01:19 PM
Re: How to get this from VBS to KiXtart
[Re: Mart]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Yeah it's the $objShape.Range that will throw that. Try this instead:
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://kixtart.org", , , "KiXtart Homepage")
|
|
Top
|
|
|
|
#197858 - 2010-02-24 01:34 PM
Re: How to get this from VBS to KiXtart
[Re: Arend_]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Also maybe try this:
; Specify an actual graphic and hyperlink
$sPicFile = "d:\gbvlogo.gif"
$sLinkFile = "http://kixtart.org"
; Create new document.
$objWord = CreateObject("Word.Application")
$oDoc = $objWord.Documents.Add
; Insert a picture.
$oILPic = $oDoc.InlineShapes.AddPicture($oDoc.Content, $sPicFile, 1)
; Add a hyperlink for the picture.
$oDoc.Hyperlinks.Add($oILPic.Range, $sLinkFile)
; Use the InlineShapes Property to reference the object.
$oHLink = $oDoc.InlineShapes(1).Hyperlink
Translated this from: http://support.microsoft.com/kb/212572
|
|
Top
|
|
|
|
#197860 - 2010-02-24 02:19 PM
Re: How to get this from VBS to KiXtart
[Re: Arend_]
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Yeah it's the $objShape.Range that will throw that. Try this instead: $objLink = $objDoc.Hyperlinks.Add($objShape, "http://kixtart.org", , , "KiXtart Homepage")
Tanks Arend. Works great. Our marketing department wanted this functionality and now I can provide them with it. Off course all credits are for you. Somehow I just cannot get my brain to take in these things and make them stick for future use. Someday I need to dig deeper into this.
Working test code:
Break on
;Create Word object
$objWord = CreateObject("Word.Application")
;Make Word visible for debuging
$objWord.Visible=1
;Add an empty document
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
;Add the picture
$objShape = $objSelection.InlineShapes.AddPicture("d:\BlogSpot.gif")
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl1.com",,, "Visit our BlogSpot pages")
$objShape = $objSelection.InlineShapes.AddPicture("d:\Twitter.gif")
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl2.com",,, "Visit our Twitter pages")
$objShape = $objSelection.InlineShapes.AddPicture("d:\Facebook.gif")
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl3.com",,, "Visit out FaceBook pages")
$objShape = $objSelection.InlineShapes.AddPicture("d:\Youtube.gif")
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl4.com",,, "Visit our YouTube Chanel")
;Exit Word.
;Disabled for debugging.
;$objWord.Quit
Sleep 10
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
|
Top
|
|
|
|
#197862 - 2010-02-24 02:35 PM
Re: How to get this from VBS to KiXtart
[Re: Mart]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Well VBS to Kix is quite easy once you get the hang of it. I also do a lot of KiX to VB.Net stuff, which is also quite logical. And nowadays VB.Net to PowerShell, which also works reasonably nice. But from PowerShell to C# is a bit harder, although most people seem to think that is an easy conversion 
Anyway, glad it works now
|
|
Top
|
|
|
|
#197938 - 2010-03-02 11:23 AM
Re: How to get this from VBS to KiXtart
[Re: Arend_]
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Ok. Seems like Word/Outlook 2K3 and 2K7 do not like the same things. Below is my working code for 2K3 and 2K7. We have a mixed environment so we have a need for two flavors of code. Lots of credits go to Arend who posted the working code for 2K7.
;Get Outlook installation path.
$olpath = ReadValue("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE", "Path")
;Get outlook version.
$olversion = GetFileVersion($olpath + "outlook.exe", "ProductVersion")
Select
;Set social network thumbnails for outlook 2K3.
;Add a space to adjust for differences in spacing between 2K3 and 2K7.
Case Left($olversion, 2) = "11"
;Add two empty lines.
$objSelection.TypeText(Chr(11))
$objSelection.TypeText(Chr(11))
;Add Youtube thumbnail.
$objShape = $objSelection.InlineShapes.AddPicture(@LDRIVE + "\tools\Youtube.gif")
;Add Youtube link to thumbnail.
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl1.com")
;Add a space to adjust for differences in spacing between 2K3 and 2K7.
$objSelection.TypeText(" ")
;Add Twitter thumbnail.
$objShape = $objSelection.InlineShapes.AddPicture(@LDRIVE + "\tools\Twitter.gif")
;Add Twitter link to thumbnail.
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl2.com")
;Add a space to adjust for differences in spacing between 2K3 and 2K7.
$objSelection.TypeText(" " )
;Add Blogspot thumbnail.
$objShape = $objSelection.InlineShapes.AddPicture(@LDRIVE + "\tools\Blogspot.gif")
;Add Blogspot link to thumbnail.
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl3.com")
;Add a space to adjust for differences in spacing between 2K3 and 2K7.
$objSelection.TypeText(" " )
;Add Facebook thumbnail.
$objShape = $objSelection.InlineShapes.AddPicture(@LDRIVE + "\tools\Facebook.gif")
;Add Facebook link to thumbnail.
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl4.com")
Case Left($olversion, 2) = "12"
;Set social network thumbnails for outlook 2K7.
;Add two empty lines.
$objSelection.TypeText(Chr(11))
$objSelection.TypeText(Chr(11))
;Add Youtube thumbnail.
$objShape = $objSelection.InlineShapes.AddPicture(@LDRIVE + "\tools\Youtube.gif")
;Add Youtube link to thumbnail.
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl1.com",,, "Visit our Youtube chanel")
;Add Twitter thumbnail.
$objShape = $objSelection.InlineShapes.AddPicture(@LDRIVE + "\tools\Twitter.gif")
;Add Twitter link to thumbnail.
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl2.com",,, "Visit our Twitter pages")
;Add Blogspot thumbnail.
$objShape = $objSelection.InlineShapes.AddPicture(@LDRIVE + "\tools\BlogSpot.gif")
;Add Blogspot link to thumbnail.
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl3.com/",,, "Visit our BlogSPot pages")
;Add Facebook thumbnail.
$objShape = $objSelection.InlineShapes.AddPicture(@LDRIVE + "\tools\Facebook.gif")
;Add Facebook link to thumbnail.
$objLink = $objDoc.Hyperlinks.Add($objShape, "http://www.someurl4.com",,, "Visit our Facebook pages")
Case 1
;Unsupported Office version installed.
EndSelect
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 601 anonymous users online.
|
|
|