Re: .xls file differs when opened via macro
This is the used code:
Option Explicit
Private Const base_TO_EXCEL As String = "C:\test"
'Private Const SHEET_NAME As String = "Sheet1"
Private Const SHEET_NAME As String = "DCF Model"
-----------------------------------------------------------------------
'* This macro assumes:
'* All values are in the same cells in _every_ single
'* excel file
'* All sheets in the excel files are named equally
'*
'* Open:
'* - Set base_TO_EXCEL to the path where the excel sheets
'* are stored in
'* - Change SHEET_NAME if the sheets are not called Valuation
Public Sub ExtractbaseData()
Application.DisplayAlerts = False
Dim fso As Scripting.FileSystemObject
Dim xlFile As Scripting.File
Dim iterationRow As Long
Dim xlAppl As Excel.Application
Dim xlSheet As Excel.Worksheet
Set fso = New Scripting.FileSystemObject
iterationRow = 1
'* Check if folder exists
If fso.FolderExists(base_TO_EXCEL) Then
'* iterate over each file
For Each xlFile In fso.GetFolder(base_TO_EXCEL).Files
If 3 < Len(xlFile.Name) Then
If "xls" = Right$(xlFile.Name, 3) Then
'* open with excel and read the values
Set xlAppl = New Excel.Application
'english
xlAppl.AddIns("analysis toolkit").Installed = True
'german xlAppl.AddIns("Analyse-Funktionen").Installed = True
'here I open the workbook with the usual command
xlAppl.Workbooks.Open (xlFile)
'this is just for debugging purposes
xlAppl.Visible = True
Set xlSheet = xlAppl.Worksheets(SHEET_NAME)
xlSheet.Unprotect ("xxxxxxxx")
xlSheet.Calculate
'just setting some values here
'* close excel
Set xlSheet = Nothing
xlAppl.DisplayAlerts = False
xlAppl.Workbooks.Close
Application.DisplayAlerts = False
iterationRow = iterationRow + 1
End If
End If
Next xlFile
Else
MsgBox "Folder does not exist. Please set the variable"
End If
Set fso = Nothing
End Sub