TerryHuangqiuguang Posted December 22, 2008 Share Posted December 22, 2008 Hi, I write a script like below to insert a hyperlink to power point, but it can't work. could you help to check what's wrong with my script.Thank you$objpres = ObjCreate("PowerPoint.Application")$PropertyClass = $objpres.Presentations$obj = $objpres.Add(True) ; Presentation obj;========Main function==============$objSlide1 = $obj.Slides.Add( $index, $layout) Sleep(1000)$objSlide1.Select()Sleep(1000)$objSlide1.Shapes.Item($intTextFrame).TextFrame.TextRange.Text = "http://yahoo.com/" ;Set the hyper link$objSlide1.Sharps.ActionSettings("PPmouseclick").action= "ppactionHyperlink"$objSlide1.Sharps.ActionSettings("PPmouseclick").hyperlink.address = "http://yahoo.com/";===========end Main function======== Link to comment Share on other sites More sharing options...
StSchnell Posted December 22, 2008 Share Posted December 22, 2008 Hello Terry Huangqiuguang, I seems to be a problem with PowerPoint. I check it direct in PPT 2003 with the following code: Dim oPPT As PowerPoint.Application Dim oPres As PowerPoint.Presentation Dim oSlide As PowerPoint.Slide Dim oShape As PowerPoint.Shape Set oPPT = CreateObject("PowerPoint.Application") oPPT.Visible = msoTrue Set oPres = oPPT.Presentations.Add(msoTrue) Set oSlide = oPres.Slides.Add(1, ppLayoutBlank) Set oShape = oSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 256, 28) '<Does not work> 'oShape.TextFrame.TextRange.Text = "http://www.google.com" 'oShape.ActionSettings(ppMouseClick).Hyperlink.Address = "http://www.google.com/" '<Automation error> 'oSlide.Shapes(1).TextFrame.TextRange.Text = "http://www.yahoo.com" 'With oSlide.Shapes(1).ActionSettings(ppMouseClick).Hyperlink ' .Address = "http://www.yahoo.com/" ' .TextToDisplay = "http://www.yahoo.com" 'End With oPPT.ActivePresentation.Save No way works. At the next step I use the macro recorder and it generates the following code: Activewindow.Selection.SlideRange.Shapes("Text Box 2").Select Activewindow.Selection.ShapeRange.TextFrame.TextRange.Select Activewindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=13).Select Activewindow.Selection.TextRange.Text = "www.yahoo.com" With Activewindow.Selection.TextRange.ActionSettings(ppMouseClick).Hyperlink .Address = "http://www.yahoo.com/" .SubAddress = "" .ScreenTip = "" .TextToDisplay = "www.yahoo.com" End With Activewindow.Selection.TextRange.Characters(Start:=21, Length:=0).Select Activewindow.Selection.Unselect This code works. I know, this is not the solution of you problem but maybe a hint. Cheers Stefan Meet me at XING Visit my private homepage Visit my commercial homepage Look at my book inter alia about AutoIt and SAP Link to comment Share on other sites More sharing options...
TerryHuangqiuguang Posted December 23, 2008 Author Share Posted December 23, 2008 Hi, Stefan Thanks. In fact, I know the code generate from Power point Macro recorder, but I got a problem when I try to repot the code from Power power macro to AuotIT, I havn't a good way to know how to combine the VBA into AutoIT. it confused me for a long time. Link to comment Share on other sites More sharing options...
TerryHuangqiuguang Posted December 23, 2008 Author Share Posted December 23, 2008 (edited) Hi, I have got the root cause and modify the function script as below. it is works. Thanks$objSlide1.Shapes.Item($intTextFrame).TextFrame.TextRange.Text = "http://yahoo.com/" ;Set the hyper link$objSlide1.Sharps.ActionSettings("PPmouseclick").action= "ppactionHyperlink";==> change to $objSlide4.Shapes(1).TextFrame.TextRange.ActionSettings(1).action= 7$objSlide1.Sharps.ActionSettings("PPmouseclick").hyperlink.address = "http://yahoo.com/";===>change to $objSlide4.Shapes(1).TextFrame.TextRange.ActionSettings(1).hyperlink.address = "http://yahoo.com.cn/"because AutoIT can not recognize "PPmouseclick" and "PPactionHyperlink" but 1 and 7. this can be found in Power point VBA obj library ;===========end Main function======== Edited December 23, 2008 by TerryHuangqiuguang Link to comment Share on other sites More sharing options...
StSchnell Posted December 23, 2008 Share Posted December 23, 2008 Hello Terry, here is another solution. 1. Code in VBA Dim oPPT As PowerPoint.Application Dim oPres As PowerPoint.Presentation Dim oSlide As PowerPoint.Slide Dim oShape As PowerPoint.Shape Set oPPT = CreateObject("PowerPoint.Application") oPPT.Visible = msoTrue Set oPres = oPPT.Presentations.Add(msoTrue) Set oSlide = oPres.Slides.Add(1, ppLayoutBlank) Set oShape = oSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 256, 28) oShape.TextFrame.TextRange.Text = "http//www.google.com" oPPT.Activewindow.Selection.SlideRange.Shapes(1).Select oPPT.Activewindow.Selection.ShapeRange.TextFrame.TextRange.Select oPPT.Activewindow.Selection.TextRange.ActionSettings(ppMouseClick).Hyperlink.Address = "http://www.google.com/" oPPT.Activewindow.Selection.Unselect 2. Code in VBScript (which can you call from AutoIt) Option Explicit Dim oPPT, oPres, oSlide, oShape Set oPPT = CreateObject("PowerPoint.Application") oPPT.Visible = True Set oPres = oPPT.Presentations.Add(True) Set oSlide = oPres.Slides.Add(1, 12) Set oShape = oSlide.Shapes.AddTextbox(1, 10, 10, 256, 28) oShape.TextFrame.TextRange.Text = "http://www.google.com" oPPT.Activewindow.Selection.SlideRange.Shapes(1).Select oPPT.Activewindow.Selection.ShapeRange.TextFrame.TextRange.Select oPPT.Activewindow.Selection.TextRange.ActionSettings(1).Hyperlink.Address = "http://www.google.com/" oPPT.Activewindow.Selection.Unselect 3. And last but not least the code for AutoIt: Dim $oPPT, $oPres, $oSlide, $oShape $oPPT = ObjCreate("PowerPoint.Application") $oPPT.Visible = True $oPres = $oPPT.Presentations.Add(True) $oSlide = $oPres.Slides.Add(1, 12) $oShape = $oSlide.Shapes.AddTextbox(1, 10, 10, 256, 28) $oShape.TextFrame.TextRange.Text = "http://www.google.com" $oPPT.Activewindow.Selection.SlideRange.Shapes(1).Select $oPPT.Activewindow.Selection.ShapeRange.TextFrame.TextRange.Select $oPPT.Activewindow.Selection.TextRange.ActionSettings(1).Hyperlink.Address = "http://www.google.com/" $oPPT.Activewindow.Selection.Unselect You see, it is very easy to translate a code from VBA to VBScript or AutoIt, it is nearly the same. Cheers Stefan Meet me at XING Visit my private homepage Visit my commercial homepage Look at my book inter alia about AutoIt and SAP Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now