Category Archives: Excel VBA

Output text files in Excel VBA

Sub LogInformation()
Const LogFileName As String = “D:\TEXTFILE.TXT”
Dim LogMessage As String
LogMessage = “123”
Dim FileNum As Integer
FileNum = FreeFile ‘ next file number
Open LogFileName For Output As #FileNum ‘ creates the file if it doesn’t exist
Print #FileNum, LogMessage ‘ write information at the end of the text file
Close #FileNum ‘ close the file
End Sub

Automate Excel faster

Turn off Screen Updating

Application.ScreenUpdating = False
at the end:
Application.ScreenUpdating = True

Turn On Manual calculation

Sub GoToManual()

Dim xlCalc As XlCalculation

xlCalc = Application.Calculation

Application.Calculation = xlCalculationManual

On Error GoTo CalcBack


Application.Calculation = xlCalc

Exit Sub


Application.Calculation = xlCalc

End Sub