2 Attachment(s)
Application Visible with more than 1 workbook
Hello,
I have a Macros that takes the workbook, saves a copy and performs copying tasks. When and how often should i CreateObject("Excel.Application") ? For every Workbook i open? how do i handle Application.Visible? Does it need to be turned True before closing the workbook?
Like the code currently operates, the opening of the workbooks is visible for a short time when excecuting the macro. After its finished and o open the created workbooks they appear grey. Does this have something to do with Application.Visible?
Code:
Option ExplicitSub PasteDiagram()
Dim PP As Object
Dim PPpres As Object
Dim xlApp As Excel.Application
Dim wbSrc As Workbook
Dim wb As Workbook
Dim k As Integer
Dim path As String
path = ActiveWorkbook.path
Set xlApp = CreateObject("Excel.Application")
Set PP = CreateObject("PowerPoint.Application")
Set wbSrc = ThisWorkbook
For k = 1 To 3
wbSrc.SaveCopyAs path & "\" & k & ".xlsm"
Set wb = Workbooks.Open(path & "\" & k & ".xlsm")
wb.Parent.DisplayAlerts = False
'wb.Parent.Visible = False
'hier ändere ich noch Daten des Workbooks
wb.Sheets("Diagramm").Range("A1") = "Änderungen wurden vorgenommen"
wb.Parent.DisplayAlerts = False
wb.Sheets("Sheet1").UsedRange.Clear
wb.Sheets("Sheet1").Visible = xlSheetVeryHidden
wb.Sheets("Sheet2").UsedRange.Clear
wb.Sheets("Sheet2").Visible = xlSheetVeryHidden
wb.Parent.DisplayAlerts = True
wb.Sheets("Diagramm").ChartObjects("Chart 2").Copy
Set PPpres = PP.Presentations.Open(path & "/Presentation1 (1).pptx", WithWindow:=False)
PPpres.Slides(1).Shapes.Paste
PPpres.SaveAs path & "\" & k & ".pptx"
wb.Close Savechanges:=True
PPpres.Save
PPpres.Close ' Savechanges:=True
Next
wbSrc.Parent.Visible = True
wbSrc.Saved = True
wbSrc.Close
PP.Quit
MsgBox "fertig"
End Sub
Attachment 30039
Attachment 30038