Hi I am working with excel 2010 and 2007. The below code works, but when I run it in 2010 after the macro has finished running I get and error message Microsoft Excel has Stopped working and excel closes. If I comment our Application.DisplayAlerts = False it works.
One other issue is that when I open the newly created excel workbook the ShowPivotTableFieldList pops up even though I have stated ActiveWorkbook.ShowPivotTableFieldList = False
Thanks in advance for assistance
L
Sub SaveAllSheetsExcel()
Dim wbk As Workbook
Dim wsh As Worksheet, vWshs
Set wbk = ActiveWorkbook
Dim newfol As String
Dim MthlyFol As String
On Error GoTo Handler
MthlyFol = Format(Date, "MMM")
newfol = Format(Date, "MMM DD YY")
'objXL.Application.DisplayAlerts = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
If Dir("\\myserver\mydirectory\ExcelDailyReports\" & MthlyFol & "\", vbDirectory) = "" Then
MkDir "\\myserver\mydirectory\ExcelDailyReports\" & MthlyFol
End If
If Dir("\\myserver\mydirectory\ExcelDailyReports\" & MthlyFol & "\" & newfol & "\", vbDirectory) = "" Then
MkDir "\\myserver\mydirectory\ExcelDailyReports\" & MthlyFol & "\" & newfol
End If
For Each wsh In wbk.Worksheets
If IsError(Application.Match(wsh.Name, vWshs, 0)) Then
wsh.Copy
ActiveWorkbook.SaveAs "\\myserver\mydirectory\ExcelDailyReports\" & MthlyFol & "\" & newfol & "\" & wsh.Name & " " & Format(Date, "MMM DD YY") & ".xls", FileFormat:=56
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.Connections("PowerPivot Data").Delete
ActiveWorkbook.Close
End If
Next wsh
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox ("All Worksheets have been Saved as Compatibility Mode .xls Files")
Exit Sub
Handler:
'ActiveWorkbook.Close SaveChanges:=False
Resume Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
One other issue is that when I open the newly created excel workbook the ShowPivotTableFieldList pops up even though I have stated ActiveWorkbook.ShowPivotTableFieldList = False
Thanks in advance for assistance
L
Sub SaveAllSheetsExcel()
Dim wbk As Workbook
Dim wsh As Worksheet, vWshs
Set wbk = ActiveWorkbook
Dim newfol As String
Dim MthlyFol As String
On Error GoTo Handler
MthlyFol = Format(Date, "MMM")
newfol = Format(Date, "MMM DD YY")
'objXL.Application.DisplayAlerts = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
If Dir("\\myserver\mydirectory\ExcelDailyReports\" & MthlyFol & "\", vbDirectory) = "" Then
MkDir "\\myserver\mydirectory\ExcelDailyReports\" & MthlyFol
End If
If Dir("\\myserver\mydirectory\ExcelDailyReports\" & MthlyFol & "\" & newfol & "\", vbDirectory) = "" Then
MkDir "\\myserver\mydirectory\ExcelDailyReports\" & MthlyFol & "\" & newfol
End If
For Each wsh In wbk.Worksheets
If IsError(Application.Match(wsh.Name, vWshs, 0)) Then
wsh.Copy
ActiveWorkbook.SaveAs "\\myserver\mydirectory\ExcelDailyReports\" & MthlyFol & "\" & newfol & "\" & wsh.Name & " " & Format(Date, "MMM DD YY") & ".xls", FileFormat:=56
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.Connections("PowerPivot Data").Delete
ActiveWorkbook.Close
End If
Next wsh
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox ("All Worksheets have been Saved as Compatibility Mode .xls Files")
Exit Sub
Handler:
'ActiveWorkbook.Close SaveChanges:=False
Resume Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub