markblandford.co.uk

Code Snippets

profile for creamyegg at Stack Overflow, Q&A for professional and enthusiast programmers

VBA - Windows API Open File Dialog

Uses the API to get a filename from the user. This differs from the built in GetOpenFilePath as it enables us to define a default directory without having to modify the user's Excel settings.

Some examples of the syntax for the strFileFilter are listed below. The first part (before & chr(0) is a description of the file type and anything can be given.

  • CSV Files
  • "CSV Files (.csv)" & chr(0) & "*.csv" & chr(0)
  • Text Files
  • "Text Files (.txt)" & chr(0) & "*.txt" & chr(0)
  • Excel Files
  • "Excel Files (*.xls, *.xlsx, *.xlsm)" & chr(0) & "*.xls; *.xlsx; *.xlsm" & chr(0)

VBA - Windows API Write to the Event Log

Code that uses the Windows API to write to the Windows Event Viewer (eventvwr.exe).

The constants listed are the valid parameters to pass into the procedure.