Computer Science 101

with:  Erik Oosterwal

Search for specific programs or algorithms:
Custom Search





Visual Basic for Applications - Open File





  ' Pop up a file selection window
  ' Make the default selection any
  ' file that fits "BWL*.XXL"
 
  varOpenFile = Application.GetOpenFilename("Data files (BWL*.XXL), BWL*.XXL")

 
  '-----------------------------------------------------------------------------------------------------------------
  ' GET NEW DATA
  ' Open the data file as a fixed width text file. The first column is read in as a date
  ' field, the other three columns are read in as "General", which means that numbers 
  ' will be treated as numbers. Select the entire input data workbook, and copy it to the 
  ' "Import Data" Sheet in this workbook. Then clear the clipboard of any information 
  ' that was copied from the input data workbook, and close that workbook. The clipboard
  ' must be cleared otherwise the user gets a message asking if they want to keep the 
  ' contents of the clipboard.
  '----------------------------------------------------------------------------------------------------------------

  Workbooks.OpenText Filename:=varOpenFile, Origin:=xlWindows, _
       StartRow:=1, DataType:=xlDelimited, ConsecutiveDelimiter:=True, _
       Space:=True, FieldInfo:=Array(Array(1, _
       9), Array(2, 4), Array(3, 1), Array(4, 1), Array(5, 1))


*The underscores at the ends of some of the lines are continuation characters that let you put a single command on multiple lines for readability.





Discuss computer algorithms and other computer science topics at the Computer Algorithms blog page.

All code and original algorithms are © Erik Oosterwal - 1987-2008
Computer Science 101

Dressing for Success