Excel DisplayAlerts
Posted: Fri May 18, 2012 11:46 am
Hello everyone
We have some vb code that saves all the tm1 sheets in a file into csv files. Upto now the user had been manually clicking on OK to save the sheets. I thought I could change this by turning off displayalerts as part of the process.
This works just fine when I am not connected to TM1, but it seems to ignore it when connected (and the user had to click ok for every save). Could anyone offer a potential cause and solution? Any help would be appreciated.
The code I have is:
We have some vb code that saves all the tm1 sheets in a file into csv files. Upto now the user had been manually clicking on OK to save the sheets. I thought I could change this by turning off displayalerts as part of the process.
This works just fine when I am not connected to TM1, but it seems to ignore it when connected (and the user had to click ok for every save). Could anyone offer a potential cause and solution? Any help would be appreciated.
The code I have is:
Code: Select all
Sub SaveMultiSheetWorkbookAsCSVFiles()
Dim path As String
Dim workbookfilename As String
Dim count As Integer
Dim myday, mymonth, myyear As Integer
Dim workbookname, sheetname, fname As String
Dim dlgFolderPicker As FileDialog
Set dlgFolderPicker = Application.FileDialog(msoFileDialogFolderPicker)
If (dlgFolderPicker.Show() = -1) Then
path = dlgFolderPicker.SelectedItems(1) & "\"
workbookfilename = ActiveWorkbook.Name ' get the current workbook name so we can switch to it as we save individual worksheets
i = InStrRev(workbookfilename, ".")
If (i > 1) Then
workbookname = Left(workbookfilename, i - 1)
Else
workbookname = workbookfilename
End If
Windows(workbookfilename).Activate
count = ActiveWorkbook.Worksheets.count
myday = Day(Date)
mymonth = Month(Date)
myyear = Year(Date)
[b]Application.DisplayAlerts = False[/b] ' LL Added 2012-05-14
For i = 1 To count
ActiveWorkbook.Worksheets(i).Select
sheetname = ActiveWorkbook.Worksheets(i).Name
Sheets(sheetname).Copy ' make a copy of the current worksheet so we can save it.
fname = path & workbookname & "-" & sheetname & "_" & myyear & "-" & mymonth & "-" & myday & ".csv"
ActiveWorkbook.SaveAs Filename:=fname, FileFormat:=xlCSV, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close False
Windows(workbookfilename).Activate ' switch back to the main workbook
Next i
[b]Application.DisplayAlerts = True[/b] ' LL Added 2012-05-14
End If
End Sub
Public Sub SetTempDirectory()
frmSetDirectory.Show
End Sub