2017-03-12

Excel Macros VBA to read data from a file and store into a string Variable

VBA to read data from a file


In this vba script you can read text from Text, HTML, JS and any other file and store into a string variable.



  1. Dim oFSO As Object
  2.     Dim oFS As Object, sText As String

  3.     Set oFSO = CreateObject("Scripting.FileSystemObject")
  4.     Set oFS = oFSO.OpenTextFile(sFile)

  5.     Do Until oFS.AtEndOfStream
  6.         sText = oFS.ReadAll()
  7.     Loop
  8.     FileToString = sText
  9.     
  10.     Set oFSO = Nothing
  11.     Set oFS = Nothing

No comments:

Post a Comment