保存powerpoint宏不运行

时间:2014-03-05 10:57:32

标签: powerpoint word-vba powerpoint-vba

我的宏VBA宏有问题。它确实有效,但现在已不再适用了。有没有人知道可能出错的地方?

 Sub SaveName()

Dim i As Integer
Dim pptcount As Integer

Dim pptapp As PowerPoint.Presentation
Dim pres As Presentations
Dim var1 As String

Set pptapp = CreateObject("Powerpoint.Application")
pptapp.Visible = True


Set pres = Application.Presentations(i)
var1 = InputBox("geef hier je maand aan")


pptcount = Application.Presentations.Count

For i = 1 To pptcount

    Application.ActivePresentation.SaveAs "X:\SSC_HR\SENS\Bedrijfsbureau\Rapportages\SENS referenten rapportage\Template_Uploaden\" & "var1" & ".ppt"

Next

End Sub

2 个答案:

答案 0 :(得分:1)

请尝试此操作,请参阅评论:

Sub SaveName()

' VBA will convert this stuff for you
' but internally they're longs
' May as well dim them correctly to start with
Dim i As Long
Dim pptcount As Long

' Dim this as Application, not as presentation:
Dim pptapp As PowerPoint.Application

Dim pres As Presentation
Dim var1 As String

Set pptapp = CreateObject("Powerpoint.Application")
pptapp.Visible = True


Set pres = Application.Presentations(i)
var1 = InputBox("geef hier je maand aan")


pptcount = Application.Presentations.Count

For i = 1 To pptcount

    Application.ActivePresentation.SaveAs "X:\SSC_HR\SENS\Bedrijfsbureau\Rapportages\SENS referenten rapportage\Template_Uploaden\" & "var1" & ".ppt"

Next

End Sub

我没有运行它,但至少它现在编译了。 ; - )

答案 1 :(得分:0)

史蒂夫说他没有运行它有几个错误,它根本不清楚它应该做什么。 不是错误,但可能不需要

设置pptapp = CreateObject(“Powerpoint.Application”)

pptapp.Visible = True

ERROR 设置pres = Application.Presentations(i)'我为零所以它将失败

错误 这是多次保存相同的演示文稿,var1不应该在“” 对于i = 1到pptcount Application.ActivePresentation.SaveAs“X:\ SSC_HR \ SENS \ Bedrijfsbureau \ Rapportages \ SENS referenten rapportage \ Template_Uploaden \”& “var1”& “.PPT” 下一步