Results 1 to 4 of 4

Thread: Excel opening .txt file code?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    31

    Excel opening .txt file code?

    Hi,

    Can someone please help me with some simple vb code for my excel macro. I wish to open a .txt file which will have a specific name based on what is contained in a certain cell in my spreadsheet. Can this be done and if so what coding would I use? I can get the a .txt file to open based on renaming the file to a certain name but I wish to be able to tell it what the name is by typing text into a cell.

    Thanks

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    31

    Re: Excel opening .txt file code?

    At the moment I have

    Dim projectname As String
    projectname = Range("C4")
    Dim referenceid As String
    referenceid = Range("C5")

    Workbooks.OpenText FileName:= _
    "C:\Documents and Settings\rkennedy\Desktop\" & projectname & "~" & referenceid & ".142", Origin:= _
    xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
    xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
    , Comma:=False, Space:=False, Other:=True, OtherChar:="=", FieldInfo _
    :=Array(Array(1, 1), Array(2, 1))

    This gives an error that it cannot find the file which will have the name cell1~cell2.142

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Excel opening .txt file code?

    Excel.Workbooks.Open "C:\path\" & Worksheets(1).Range("A1").Value

    worked fine for me..

    try doing it with a regular name file.. like Test.txt
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Excel opening .txt file code?

    Excel VBA question moved to Office Development.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width