• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

appending txt file

N PADMAJA

New Member
Code:
 With ActiveSheet.QueryTables.Add(Connection:="TEXT;D:\new\product\1.txt" _
        , Destination:=Range("$A$1"))

I am using the above code to append a text file and in the code itself giving the entire path.

without mentioning the current directory path, can i do the appending from the text file available in the current directory,
 
N Padmaja

Firstly, Welcome to the Chandoo.org Forums

Have you tried leaving off the directory information?

Code:
With ActiveSheet.QueryTables.Add(Connection:="TEXT;1.txt" _
        , Destination:=Range("$A$1"))
 
N Padmaja

Firstly, Welcome to the Chandoo.org Forums

Have you tried leaving off the directory information?

Code:
With ActiveSheet.QueryTables.Add(Connection:="TEXT;1.txt" _
        , Destination:=Range("$A$1"))


when i tried the above code leaving directory information, i am getting the following error

Run time error 1004

excel can not find the text file and debug is showing the below line in yellow colour

.Refresh BackgroundQuery:=False


▬▬▬▬▬▬▬▬▬ Mod edit : thread moved to appropriate forum !
 
Hello Padmaja.

Hope you are doing good..Welcome to the forum.

As you are asking without mentioning the current directory path, can i do the appending from the text file available in the current directory,


Yes you can...Please put the entire path in the Sheet1 in Any cell and refer as a variable
Code:
Dim Mypath as string

Mypath=Sheet1("A1").value
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Mypath &" _"
        , Destination:=Range("$A$1"))


Hope this works for you...If not please upload file..Happy to help you...Monty
 
thanks for your reply. with this revised code, i am getting compile error message.
text file, macro file and error file are attached.
 

Attachments

  • 1.txt
    87 bytes · Views: 1
  • aaaa_test_macro.txt
    1.2 KB · Views: 1
  • error.docx
    208 KB · Views: 1
Monty

You are rocking...i was just following the question asked by padmaja madam and you have provided a complete application types...excellent.
 
Back
Top