gpt4 book ai didi

vba - 单步执行我的代码有效,运行我的代码会给出对象 "Method ' 的 'Selection' ShapeRange 失败”错误消息

转载 作者:行者123 更新时间:2023-12-04 21:07:34 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





PowerPoint VBA does not recognize Excel table during run

(1 个回答)


4年前关闭。




逐步浏览我的 Code Works,它完全符合我的要求(从 Excel 中的各种表格、文本框和图像创建一个 powerpoint 幻灯片)。但是运行代码不起作用。我认为这与时间无关,因为我在粘贴范围后包含了时间暂停。当代码到达“newpowerpoint.activewindow.selection ...”行时,我收到“对象'Selection'的方法'ShapeRange'失败”错误消息。

任何帮助将不胜感激。

谢谢!

Sub CreatePowerPoint()

Worksheets("2 Source of Change and Switchi").Select

Dim newPowerPoint As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide
Dim cht As Excel.ChartObject

On Error Resume Next
Set newPowerPoint = GetObject(, "PowerPoint.Application")
On Error GoTo 0

newPowerPoint.Visible = True

newPowerPoint.ActiveWindow.View.GotoSlidenewPowerPoint.ActivePresentation.Slides.count
Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.count)


'######################The Code below Copies and Pastes in My Values#####################

Worksheets("3 Switching details – Actual v").Select


ActiveSheet.Range(Range("D51"), Range("D51").End(xlDown)).Copy
newPowerPoint.CommandBars.ExecuteMso ("PasteExcelTableSourceFormatting")
Application.Wait (Now + TimeValue("0:00:01"))

newPowerPoint.ActiveWindow.Selection.ShapeRange.Left = 640

end sub

最佳答案

我已经使用此代码来解决问题。似乎需要某种中断才能正确运行代码。

    With Application.ActiveWindow.Selection
MsgBox "Click ok"
End With

关于vba - 单步执行我的代码有效,运行我的代码会给出对象 "Method ' 的 'Selection' ShapeRange 失败”错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31003461/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com