View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Kurt Farrar Kurt Farrar is offline
external usenet poster
 
Posts: 2
Default Import Text File w/ VBA

If you just want to open the text file you should use the following command
in your VBA:

Dim sCompany As String
Dim sDivision As String
Dim sDate As String
Dim sFilename As String

sCompany = Range("A1")
sDivision = Range("A2")
sDate = Replace(Range("A3"), "/", "")
sFilename = "C:\" & sCompany & "\" & sDivision & "\" & sDate & ".txt"


Workbooks.OpenText Filename:=sFilename

In the above example you should replace C:\ with the starting point of your
folder structure. You'll notice Replace(Range("A3"), "/", "") this ensures
that if the date is entered dd/mm/yyyy or mm/dd/yyyy ie. with slashes, which
are invalid for filenames, then they are removed.

I hope this helps.

--
Kurt Farrar
..NET Developer & Computer Enthusiast



"Suzseb" wrote:

I am trying to set up a macro to import a specific text file based on the
information the user puts into specific cells. They imput the company,
division and date and this generates a path & filename in a cell in the
spreadsheet. How can I get that path & filename into the macro? I've tried
quite a few options but with no success.

Thanks,
--
Suz