Jump to content

Recommended Posts

Posted

Has anyone used this function from the PowerPoint.au3? I am having trouble just figuring out how to list the parameters. This is from the help file for PowerPoint.au3:

_PPT_ExcelImport

Import a Range of cells or a Chart from Excel and insert as Table or Picture into a Slide.
_PPT_ExcelImport($oPresentation, $vSlide, $vShape, $oObject, $iFlag)

Parameters:
  $oPresentation - Object of the presentation to process.
  $vSlide - Single Slide to process. Please see _PPT_SlideRangeSet for possible values.
  $vShape - Table shape to copy the Excel cells to. If needed the table will be expanded to fit the Excel Cell Range.
  If set to Default a new Table Shape will be created. This parameter is ignored for $iFlag = 2.
  $oObject - Range object of the Excel cells to process or Excel Chart object.
  $iFlag - Processing options. Can be a combination of the following values:
     1 - Insert the Range as a new Picture Shape
     2 - Insert the Range as a new Table Shape (editable)
     3 - Insert a Chart as a new Picture Shape

In my code I previously selected and copied a range of cells in my Excel file and put them into $oRange:

Local $oRange = $oWorkbook1.ActiveSheet.Range("A3:K420")

I don't know if that will work _PPT_ExcelImport but I am using it as my $oObject. I also tried using just the range "A3:K420" but no luck. 

Here is the line with the _PPT_ExcelImport:

_PPT_ExcelImport($oPresentation1, 1, Default, $oRange, 2)

The error I get with this is:

"C:\Program Files (x86)\AutoIt3\Include\PowerPoint.au3" (1581) : ==> The requested action with this object has failed.:
$aSlides[$i - 1] = $oSlide.Shapes.AddTable($vP1, $vP2, $iX1, $iY1, $iX2, $iY2)
$aSlides[$i - 1] = $oSlide.Shapes^ ERROR

 

I can't find any examples on how to use this nor any posts from anyone talking about it. Anyone able to help me with this?

Posted (edited)
Posted

Add 

_PPT_ErrorNotify(2)

at the top of your script and you will get detailed error information.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

@water @Nine

I am having an issue where _PPT_Close is not closing PowerPoint. I have it first use _PPT_PresentationClose to close the presentation and then use _PPT_Close to close PowerPoint. That worked and it also removed any running instance of PowerPoint as well. I do the same thing with Excel and it works fine. 

Then I added the code using _PPT_ExcelImport and now the _PPT_Close is not working. _PPT_PresentationClose is still working. Any ideas?

 

; Open the PowerPoint Presentation
         Global $oPPT = _PPT_Open()
         If @error Then Exit MsgBox($MB_SYSTEMMODAL, "MS Excel Data Workflow", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
         ; Open PowerPoint Presentation
         Global $oPresentation1 = _PPT_PresentationOpen($oPPT, @ScriptDir & "\PowerPoint_Presentation.pptx")
         If @error Then
             MsgBox($MB_SYSTEMMODAL, "MS Excel Data Workflow", "Error opening workbook '" & @ScriptDir & "\PowerPoint_Presentation.pptx'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
             _PPT_Close($oPPT)
             Exit
          EndIf

         ; start time for paste.
         WinWaitActive("PowerPoint_Presentation.pptx - PowerPoint")
         Local $hTimer = TimerInit()
         GetTime()
         $T1[2] = $GTime

         ; Paste content to Presentation
         Global $oSlide = $oPresentation1.Slides(1)
         _PPT_ExcelImport($oPresentation1, $oSlide, Default, $oWorkbook1.Sheets(1).Range("A3:K42"), 1)

         ; end time for paste.
         Global $iTime = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit.
         ConvertTime()
         $T3[2] = $CTime
         GetTime()
         $T2[2] = $GTime

         ; Close PowerPoint
         Sleep(1000)
         _PPT_PresentationClose($oPresentation1, False)
         ;Sleep(1000)
         _PPT_Close($oPPT, False)
         If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_Close Example 1", "Error closing the PowerPoint application." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

         ; Close Excel
         Sleep(1000)
         _Excel_BookClose($oWorkbook1, False)
         Sleep(1000)
         _Excel_Close($oExcel, False, True)

 

Posted

What is the value of @error and @extended after _PPT_PresentationClose?

Is PowerPoint already running when you start your script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

@water

@error and @extended are both 0.

PowerPoint is not running. My code for opening it is at the top of the example code I included in my previous post if you want to see it.

Posted

I created this runable script from your example code - it works just fine.

  • Which version of PowerPoint do you run?
  • Which version of Windows do you run?
  • Which version of AutoIt do you use?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

I am testing with PowerPoint from Office 2013. Will eventually run it with Office 365 locally installed PowerPoint.

Windows 11

AutoIT is v3.3.14.5

 

Posted

_PPT_Open always raises a COM "error". 
It tries to connect to a running PowerPoint instance.
If there is none you get this "error".

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Office 2013 is quite old. I can imagine that the problem does not exist with Office 2016 or later.
I'm running Office 2016 on Windows 10. Everything works just fine.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

@water I compiled my script and moved it to a VM running Windows 10 with the last version of Office 365 installed. It errors out on _PPT_ExcelImport over half the time. Sometimes it works and I don't know why. Below is the entire script in case some part of it affects the import function. I also attached a screenshot of the error.

#include <GuiConstants.au3>
#include <MsgBoxConstants.au3>
#include <Excel.au3>
#include <PowerPoint.au3>
#include <File.au3>
#include <ScreenCapture.au3>
#include <WinAPIError.au3>
#include <BlockInputEx.au3>
_PPT_ErrorNotify(2)

Dim $show = 0, $Child_[6], $children = 5
Global $sWLName = "MS Excel Data Workflow"
Global $sRegPathx86 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", $sRegPathx64 = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Global $sSoftware1 = "Microsoft 365", $sSoftware2 = "Microsoft Access Database Engine 2016"
Global $bSearch[3], $sErrorMSG[2]
Global $Page, $Runs = "5", $Wait = "15", $Task = "1", $TR, $gTime = "", $cTime = "", $sErrorText = ""
;Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

$Main = GUICreate($sWLName, 516, 323, (@DesktopWidth - 516) / 2, (@DesktopHeight - 323) / 2)

$Button_1 = GUICtrlCreateButton("&Next >", 420, 290, 80, 25)
$Button_2 = GUICtrlCreateButton("&Finish", 420, 290, 80, 25)
$Button_3 = GUICtrlCreateButton("", 10, 270, 495, 3, -1, $WS_EX_STATICEDGE)
GUICtrlSetState($Button_2, $GUI_HIDE)
WinSetOnTop ($sWLName, "", 1)
GUISetState()

$Child_[1] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
$Label_1 = GuiCtrlCreateLabel("Required Software for this Workload:", 10, 10, 290, 30)
GUICtrlSetFont(-1, 10, 650)
$Label_2 = GuiCtrlCreateLabel($sSoftware1, 10, 40, 290, 20)
$Label_3 = GuiCtrlCreateLabel($sSoftware2, 10, 60, 290, 20)
$Label_4 = GuiCtrlCreateLabel("Click Next to get started.", 10, 210, 290, 20)
GUISetState()

$Child_[2] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
$Label_1 = GuiCtrlCreateLabel("Check for Required Software", 10, 10, 290, 30)
GUICtrlSetFont(-1, 10, 650)
$Label_2 = GuiCtrlCreateLabel ($sSoftware1 & ":", 10, 40, 260, 20)
GUICtrlSetFont(-1, 8.5, 650)
$Label_2r = GuiCtrlCreateLabel ("", 10, 60, 460, 20)
$Label_3 = GuiCtrlCreateLabel ($sSoftware2 & ":", 10, 80, 260, 20)
GUICtrlSetFont(-1, 8.5, 650)
$Label_3r = GuiCtrlCreateLabel ("", 10, 100, 460, 20)
$Label_4r = GuiCtrlCreateLabel ("", 10, 200, 460, 50)
GUICtrlSetColor(-1, 0xFF0000) ; Red
GUICtrlSetFont(-1, 8.5, 650)
GUISetState(@SW_HIDE)

$Child_[3] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
$Label_1 = GuiCtrlCreateLabel("Input Runs and Wait Time", 10, 10, 290, 30)
GUICtrlSetFont(-1, 10, 650)
$Label_2 = GuiCtrlCreateLabel ("Number of Runs", 10, 40, 120, 20)
$Input_1 = GUICtrlCreateInput($Runs, 10, 55, 50, 20, $ES_NUMBER)
$Label_3 = GuiCtrlCreateLabel ("Wait time (seconds)", 10, 90, 120, 20)
$Input_2 = GUICtrlCreateInput($Wait, 10, 105, 50, 20, $ES_NUMBER)
GUISetState(@SW_HIDE)

$Child_[4] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
$Label_1 = GuiCtrlCreateLabel("Test in Process", 10, 10, 290, 30)
GUICtrlSetFont(-1, 10, 650)
$Label_1b = GuiCtrlCreateLabel ("Press ESC key to exit test.", 10, 30, 230, 20)
$Label_2 = GuiCtrlCreateLabel ("Run", 10, 60, 30, 20)
$Label_2t = GuiCtrlCreateLabel ("", 40, 60, 40, 20)
$Label_3 = GuiCtrlCreateLabel ("Task", 10, 80, 30, 20)
$Label_3t = GuiCtrlCreateLabel ("", 40, 80, 40, 20)
$Label_4t = GuiCtrlCreateLabel ("", 10, 100, 440, 20)
GUISetState(@SW_HIDE)

$Child_[5] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
$Label_1 = GuiCtrlCreateLabel("Complete", 10, 10, 290, 30)
GUICtrlSetFont(-1, 10, 650)
$Label_2 = GuiCtrlCreateLabel ("Results output to:", 10, 40, 230, 20)
$Label_3 = GuiCtrlCreateLabel ("", 10, 60, 480, 60)


GUISetState(@SW_HIDE)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            Set_Next()
            Task_Run()
        Case $msg = $Button_2
            ExitLoop

    EndSelect
WEnd

;--------- Functions -------------------

Func Set_Next()
   For $x = 1 To $children - 1
      $Nwin = WinGetState($Child_[$x])
      $Page = $x
      If $Page = 4 Then
         GUICtrlSetState($Button_2, $GUI_SHOW)
         GUICtrlSetState($Button_1, $GUI_HIDE)
      EndIf
      If $Nwin > 5 Then
         GUISetState(@SW_HIDE, $Child_[$x])
         GUISetState(@SW_SHOW, $Child_[$x + 1])
         Return
      EndIf
   Next
EndFunc

Func Task_Run()
   ; Perform required software check.
   If $Page = 1 Then
      _RegSearch($sSoftware1)
      If $bSearch[0] = "True" Then
         GUICtrlSetData($Label_2r, $bSearch[1] & "   Version: " & $bSearch[2] & "  installed.")
         $bSearch[0] = ""
      Else
         GUICtrlSetData($Label_2r, $sSoftware1 & "  was not found.")
         GUICtrlSetData($Label_4r, "Refer to the Getting Started Guide for instructions on how to install the missing software.")
         GUICtrlSetState($Button_2, $GUI_SHOW)
         GUICtrlSetState($Button_1, $GUI_HIDE)
      EndIf
      _RegSearch($sSoftware2)
      If $bSearch[0] = "True" Then
         GUICtrlSetData($Label_3r, $bSearch[1] & "   Version: " & $bSearch[2] & "  installed.")
         $bSearch[0] = ""
      Else
         GUICtrlSetData($Label_3r, $sSoftware2 & "  was not found.")
         GUICtrlSetData($Label_4r, "Refer to the Getting Started Guide for instructions on how to install the missing software.")
         GUICtrlSetState($Button_2, $GUI_SHOW)
         GUICtrlSetState($Button_1, $GUI_HIDE)
      EndIf
   EndIf

   ;Perform task timings.
   If $Page = 3 Then
      Global $T1[$Runs][3], $T2[$Runs][3], $T3[$Runs][3], $T4[$Runs]
      GUICtrlSetState($Button_1, $GUI_HIDE)
      ;Block keyboard and Mouse input except for Esc key.
      ;HotKeySet("{ESC}", "_Quit")
      ;_BlockInputEx(1, "{ESC}")

      ; Open the Excel workbook
      $Runs = GUICtrlRead($Input_1)
      $Wait = GUICtrlRead($Input_2)*1000
      For $TR = 0 To $Runs-1
         $Task = "1"
         GUICtrlSetData($Label_2t, $TR+1 & " of " & $Runs)
         GUICtrlSetData($Label_3t, $Task & " of 3")
         GUICtrlSetData($Label_4t, "Open Excel Workbook")
         Global $oExcel = _Excel_Open()
         If @error Then
            $sErrorMSG[0] = _WinAPI_GetLastErrorMessage(@error)
            $sErrorMSG[1] = "Error creating the Excel application object."
            MsgBox($MB_SYSTEMMODAL, $sWLName, "Task " & $Task & @CRLF & $sErrorMSG[1] & @CRLF & "@error = " & @error & ", @extended = " & @extended & ".  " & $sErrorMSG[0])
            _ScreenCapture_CaptureWnd(@ScriptDir & "\" & $sWLName & "_Error.jpg", "")
            Exit
         EndIf
         ; Open Excel Workbook
         Global $oWorkbook1 = _Excel_BookOpen($oExcel, @ScriptDir & "\Excel_Workbook.xlsm")
         If @error Then
            $sErrorMSG[0] = _WinAPI_GetLastErrorMessage(@error)
            $sErrorMSG[1] = "Error opening workbook '" & @ScriptDir & "\Excel_Workbook.xlsm'."
            MsgBox($MB_SYSTEMMODAL, $sWLName, "Task " & $Task & @CRLF & $sErrorMSG[1] & @CRLF & "@error = " & @error & ", @extended = " & @extended & ".  " & $sErrorMSG[0])
            _ScreenCapture_CaptureWnd(@ScriptDir & "\" & $sWLName & "_Error.jpg", "")
            _Excel_Close($oExcel, False, True)
            Exit
         EndIf

         ; start time for first macro.
         Local $hTimer = TimerInit()
         GetTime()
         $T1[$TR][0] = $GTime
         ;ConsoleWrite("Create Calc " & $T1[$TR][0] & @CRLF)

         ; Run first macro
         GUICtrlSetData($Label_4t, "Run CreateCalculations Macro")
         $oExcel.Run("CreateCalculations")

         ; end time for first macro.
         Global $iTime = Round(TimerDiff($hTimer)/10,0); Find the difference in time from the previous call of TimerInit.
         $T4[$TR] = $iTime
         ConvertTime2()
         ;ConsoleWrite("task time " & $T4[$TR] & "  " & $iTime & "  " & $iTime/100 & @CRLF)
         $T3[$TR][0] = $CTime
         ;ConsoleWrite("task time " & $T3[$TR][0] & @CRLF)
         GetTime()
         $T2[$TR][0] = $GTime
         ;ConsoleWrite("End time " & $T2[$TR][0] & @CRLF)
         $Task += 1

         ; start time for second macro.
         GUICtrlSetData($Label_3t, $Task & " of 3")
         Local $hTimer = TimerInit()
         GetTime()
         $T1[$TR][1] = $GTime
         ;ConsoleWrite("Create Pivot " & $T1[$TR][1] & @CRLF)

         ; Run second macro
         GUICtrlSetData($Label_4t, "Run CreatePivotTable Macro")
         $oExcel.Run("CreatePivotTable")

         ; end time for second macro.
         Global $iTime = Round(TimerDiff($hTimer)/10,0) ; Find the difference in time from the previous call of TimerInit.
         $T4[$TR] += $iTime
         ;ConsoleWrite("task time " & $T4[$TR] & "  " & $iTime & "  " & $iTime/100 & @CRLF)
         ConvertTime2()
         $T3[$TR][1] = $CTime
         ;ConsoleWrite("task time " & $T3[$TR][1] & @CRLF)
         GetTime()
         $T2[$TR][1] = $GTime
         ;ConsoleWrite("End time " & $T2[$TR][1] & @CRLF)
         $Task += 1

         ; Open the PowerPoint Presentation
         GUICtrlSetData($Label_3t, $Task & " of 3")
         GUICtrlSetData($Label_4t, "Open PowerPoint Presentation")
         Global $oPPT = _PPT_Open()
         If @error Then
            $sErrorMSG[1] = "Error creating the PowerPoint application object."
            HandleError()
         EndIf
         ; Open PowerPoint Presentation
         Global $oPresentation1 = _PPT_PresentationOpen($oPPT, @ScriptDir & "\PowerPoint_Presentation.pptx")
         If @error Then
            $sErrorMSG[1] = "Error opening presentation '" & @ScriptDir & "\PowerPoint_Presentation.pptx'."
            HandleError()
            _PPT_Close($oPPT)
         EndIf
         Sleep(1000)

         ; start time for paste.
         ;WinWaitActive("PowerPoint_Presentation.pptx - PowerPoint")
         Local $hTimer = TimerInit()
         GetTime()
         $T1[$TR][2] = $GTime
         ;ConsoleWrite("Paste " & $T1[$TR][2] & @CRLF)

         ; Paste content to Presentation
         ;Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
         GUICtrlSetData($Label_4t, "Paste Cells into Presentation")
         Global $oSlide = $oPresentation1.Slides(1)
         _PPT_ExcelImport($oPresentation1, $oSlide, Default, $oWorkbook1.Sheets(1).Range("A3:K42"), 1)
         If @error Then
            $sErrorMSG[1] = "Error pasting in presentation '" & @ScriptDir & "\PowerPoint_Presentation.pptx'."
            HandleError()
            _PPT_PresentationClose($oPresentation1, False)
            _PPT_Close($oPPT)
         EndIf
         ;Global $oErrorHandler = ""

         ; end time for paste.
         Global $iTime = Round(TimerDiff($hTimer)/10,0) ; Find the difference in time from the previous call of TimerInit.
         $T4[$TR] += $iTime
         ConvertTime2()
         $T3[$TR][2] = $CTime
         ConsoleWrite("task time " & $T3[$TR][2] & @CRLF)
         GetTime()
         $T2[$TR][2] = $GTime
         ;ConsoleWrite("End time " & $T2[$TR][2] & @CRLF)
         ;ConsoleWrite("total time " & $T4[$TR] & @CRLF)

         ; Close PowerPoint
         GUICtrlSetData($Label_4t, "Close Presentation and Workbook")
         Sleep(500)
         _PPT_PresentationClose($oPresentation1, False)
         Sleep(500)
         ;Local $hWnd = WinWait("PowerPoint")
         ;Local $iPID = WinGetProcess($hWnd)
         _PPT_Close($oPPT, False)
         ;ProcessClose($iPID)

         ; Close Excel
         Sleep(500)
         _Excel_BookClose($oWorkbook1, False)
         Sleep(500)
         ;Local $hWnd = WinWait("Excel")
         ;Local $iPID = WinGetProcess($hWnd)
         _Excel_Close($oExcel, False, True)
         ;ProcessClose($iPID)
         If $TR < $Runs-1 Then
            GUICtrlSetData($Label_4t, "Waiting " & $Wait/1000 & " seconds before next run")
            Sleep($Wait)
         EndIf
      Next
      Set_Next()
      ;_BlockInputEx(0) ; Unblock keyboard and mouse input
   EndIf
   If $Page = 4 Then
      ; Output time results
      Local $output_file = @ScriptDir & "\MS Excel Data Workflow Output.csv"
      If FileExists($output_file) Then
         FileDelete($output_file)
      EndIf
      _FileCreate($output_file)
      FileOpen($output_file, 1)
      FileWrite($output_file, "Run,Task Name,Start Time,End Time,Task Time" & @CRLF)
      For $OP = 0 To $Runs-1
         FileWrite($output_file, "Run " & $OP+1 & ",Task 1," & $T1[$OP][0] & "," & $T2[$OP][0] & "," & $T3[$OP][0] & @CRLF)
         FileWrite($output_file, "Run " & $OP+1 & ",Task 2," & $T1[$OP][1] & "," & $T2[$OP][1] & "," & $T3[$OP][1] & @CRLF)
         FileWrite($output_file, "Run " & $OP+1 & ",Task 3," & $T1[$OP][2] & "," & $T2[$OP][2] & "," & $T3[$OP][2] & @CRLF)
         $iTime = $T4[$OP]
         ;ConsoleWrite("task time " & $T4[$OP] & "  " & $iTime & @CRLF)
         ConvertTime2()
         FileWrite($output_file, "Run " & $OP+1 & " Total Time,,,," & $CTime & @CRLF)
      Next
      FileClose($output_file)
      GUICtrlSetData($Label_3, @ScriptDir & "\MS Excel Data Workflow Output.csv")
   EndIf
EndFunc

Func _IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
 EndFunc   ;==>_IsChecked

Func _RegSearch($sSearch)
    Local $sKey, $sSubKey = "", $i = 1
    While 1
        $sSubKey = RegEnumKey($sRegPathx86, $i)
            If @error Then ExitLoop
        $sDisplay = RegRead($sRegPathx86 & $sSubKey, "DisplayName")
        If $sDisplay <> "" And StringInStr($sDisplay, $sSearch) Then
           $bSearch[0] = "True"
           $bSearch[1] = RegRead($sRegPathx86 & $sSubKey, "DisplayName")
           $bSearch[2] = RegRead($sRegPathx86 & $sSubKey, "DisplayVersion")
           ExitLoop
           Return $bSearch
        EndIf
        $i += 1
     WEnd
         Local $sKey, $sSubKey = "", $i = 1
    While 1
        $sSubKey = RegEnumKey($sRegPathx64, $i)
            If @error Then ExitLoop
        $sDisplay = RegRead($sRegPathx64 & $sSubKey, "DisplayName")
        If $sDisplay <> "" And StringInStr($sDisplay, $sSearch) Then
           $bSearch[0] = "True"
           $bSearch[1] = RegRead($sRegPathx64 & $sSubKey, "DisplayName")
           $bSearch[2] = RegRead($sRegPathx64 & $sSubKey, "DisplayVersion")
           ExitLoop
           Return $bSearch
        EndIf
        $i += 1
     WEnd
    Return $bSearch
 EndFunc

 Func GetTime()
   Local $Hr = Int(Number(@HOUR))
   Local $Min = Int(Number(@MIN))
   Local $Sec = Int(Number(@SEC))
   Local $MSc = Round(Int(Number(@MSEC)/10),0)
   $GTime = StringFormat("%02i",$Hr) & ":" & StringFormat("%02i",$Min) & ":" & StringFormat("%02i",$Sec) & ":" & StringFormat("%02i",$MSc)
EndFunc

Func ConvertTime()
   $hour = Floor($iTime / 3600000)
   $remanH = Mod($iTime, 3600000)
   $min = Floor($remanH / 60000)
   $remanM = Mod($remanH, 60000)
   $sec = Floor($remanM / 1000)
   $remanS = Mod($remanM, 1000)
   $msec = Round($remanS/100, 0)
   $CTime = StringFormat("%02i",$hour) & ":" & StringFormat("%02i",$min) & ":" & StringFormat("%02i",$sec) & ":" & StringFormat("%02i",$msec)
EndFunc

Func ConvertTime2()
   $hour = Floor($iTime / 360000)
   $remanH = Mod($iTime, 360000)
   $min = Floor($remanH / 6000)
   $remanM = Mod($remanH, 6000)
   $sec = Floor($remanM / 100)
   $remanS = Mod($remanM, 100)
   $msec = Round($remanS, 0)
   $CTime = StringFormat("%02i",$hour) & ":" & StringFormat("%02i",$min) & ":" & StringFormat("%02i",$sec) & ":" & StringFormat("%02i",$msec)
EndFunc

Func HandleError()
   $sErrorMSG[0] = _WinAPI_GetLastErrorMessage(@error)
   MsgBox($MB_SYSTEMMODAL, $sWLName, "Task " & $Task & @CRLF & $sErrorMSG[1] & @CRLF & "@error = " & @error & ", @extended = " & @extended & ".  " & $sErrorMSG[0])
   _ScreenCapture_CaptureWnd(@ScriptDir & "\" & $sWLName & "_Error.jpg", "")
   _Excel_BookClose($oWorkbook1, False)
   _Excel_Close($oExcel, False, True)
   Exit
EndFunc

Func _ErrFunc($oError)
    MsgBox($MB_SYSTEMMODAL, $sWLName," Task " & $Task & @CRLF & "(" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
   @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
   @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
   @TAB & "err.description is: " & @TAB & $oError.description & @CRLF)
   _ScreenCapture_CaptureWnd(@ScriptDir & "\" & $sWLName & "_Error.jpg", "")
   _Excel_BookClose($oWorkbook1, False)
   _Excel_Close($oExcel, False, True)
   Exit
EndFunc   ;==>_ErrFunc

Func _Quit()
    Exit
EndFunc

 

error.png

Posted

I do not know the cause of the problem. MS does give us much information.

So I would modify _PPT_ExcelImport and replace

$oObject.CopyPicture($xlScreen, $xlPicture)

with

$oObject.CopyPicture($xlScreen, $xlBitmap)

Maybe this solves the problem?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

@water I will try this. 

Alternatively, I originally planned to use _Excel_RangeCopyPaste to copy the cells from Excel but I couldn't find a way to paste them into PowerPoint using a different UDF/COM function. Do you of a UDF/COM function that would let me paste from the clipboard into PowerPoint?

 

Edit: I ran the change and it seems like it is failing less (hard to know for sure since I didn't run it hundreds of times) but it does still fail sometimes with the same error info.

Edited by PeterlFF
Posted

Seems this post describes your problem: excel - CopyPicture method of range class failed - sometimes - Stack Overflow

Can you please test the suggested code changes?
I will add the solution that works for you to the PPT UDF.

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

AutoIt provides function _ClipBoard_IsFormatAvailable to check the format of the data in the Clipboard.
The clipboard formats can be found here: https://docs.microsoft.com/en-us/windows/win32/dataxchg/standard-clipboard-formats

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

@waterThanks for the info and for your help.

I made a couple changes to the PowerPoint.au3 and ran my code with 20 runs (so it ran the copy/paste 20 times in a row) without any errors. I ran it again and still no error.

For _PPT_ExcelImport  I replaced $xlPicture with $xlBitmap and I added $oObject.Copy right before the CopyPicture line.

I tried using Sleep(50) instead of $oObject.Copy but still got the error. Here is the section of code with the 2 changes that made my code work.

Case 1     ; Copy Range as Picture
            $oObject.Copy
            $oObject.CopyPicture($xlScreen, $xlBitmap)
            If @error Then Return SetError(2, @error, 0)
            ; Insert the picture into the Slide as a new Shape
            $oShape = $oSlide.Shapes.Paste
            If @error Then Return SetError(3, @error, 0)

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...