Page 1 of 1 1
Topic Options
#197781 - 2010-02-15 11:57 AM How to get this from VBS to KiXtart
Mart Moderator Offline
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.

 Code:
    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:
 Code:
'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
#197784 - 2010-02-15 11:03 PM Re: How to get this from VBS to KiXtart [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
I've been trying and testing but crashed en burned every freaking time.
It should not be so hard to get this done I guess. Maybe it is my VBS knowledge..........or the lack of it.

I'll give Glen's script in the vault a try and see if the results will fit our needs. If anyone has any bright ideas then they are more than welcome.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#197785 - 2010-02-15 11:08 PM Re: How to get this from VBS to KiXtart [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Post your kix code... I'm not sure I'll have any suggestions, but its better than me recreating what you've already done.
Top
#197786 - 2010-02-15 11:34 PM Re: How to get this from VBS to KiXtart [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Like I said I've been trying and trying but no luck. Below is what I have so far as a test script. I had different versions of it but they made no sense. Obviously this is not the main script. I’m not going to add this until this is fully working. I'm having some issues with the line that adds the hyperlink and the line that sets the hyperlink (line 15 and 18).

One day I need to learn this VBS stuff \:\(

 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:\picture.gif")

;Add a hyperlink For the picture.
$objDoc.Hyperlinks.Add Anchor:=$objShape.Range, Address:="http://www.someurl.com"

;Use the InlineShapes Property To reference the Object.
$oHLink = $objDoc.InlineShapes(1).Hyperlink

;Exit Word.
;Disabled for debugging.
;$objWord.Quit

Sleep 10
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#197787 - 2010-02-16 01:11 AM Re: How to get this from VBS to KiXtart [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
We turn the image into a link for several clients, so I know it's possible. It's all in how you create the template.

At one client, there are several images and two web site URLs. There is one template for each division (web site), so the URL is hard-coded into the template. This means we don't have to rely on the URL being in the AD properties. The image is department-specific (an advertisement for their featured travel package), with about 12 images across 260+ departments.

Feel free to PM/Email me if you have specific Q's.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197845 - 2010-02-23 09:27 AM Re: How to get this from VBS to KiXtart [Re: Glenn Barnas]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Try this:
 Code:
$objDoc.Hyperlinks.Add("Anchor:="+$objShape.Range, "Address:=http://www.someurl.com")

Top
#197846 - 2010-02-23 10:30 AM Re: How to get this from VBS to KiXtart [Re: Arend_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Thanks Arend. I changed it a bit (removed the Anchor: and the Address: parts) and now it adds a link but it also throws an error for the line that adds the link about IDispatch pointers not allowed in expressions.

 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:\gbvlogo.gif")


$objDoc.Hyperlinks.Add($objShape.Range, "http://someurl.com")


;Exit Word.
;Disabled for debugging.
;$objWord.Quit

Sleep 10
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#197857 - 2010-02-24 01:19 PM Re: How to get this from VBS to KiXtart [Re: Mart]
Arend_ Moderator Offline
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:
 Code:
$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_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Also maybe try this:
 Code:
   ; 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 Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Originally Posted By: apronk
Yeah it's the $objShape.Range that will throw that.
Try this instead:
 Code:
$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:
 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_ Moderator Offline
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 Moderator Offline
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.

 Code:
;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
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 533 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.069 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org