Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open TXT file in Excel via hyperlink

Status
Not open for further replies.

ranebow

Programmer
Mar 8, 2003
110
US
I posted this earlier and had something misleading in the subject line.


In Excel, I've done a hyperlink to a TXT file that is downloaded via another software package. Is there any way to force the link to open the TXT file via Excel instead of Notepad?
 
The text file will always open in Notepad because it is the associated application.

You could change the association to Excel, but this will cause all text files to open in Excel, and Excel will start the import wizard, asking you to define separators etc.

Cheers,
Dave

Probably the only Test Analyst on Tek-Tips...therefore whatever it was that went wrong, I'm to blame...

animadverto vos in Abyssus!

Take a look at Forum1393 & sign up if you'd like
 
I am sure the real Excel folks will do better, but you can bring in the contents of a text file using FileSystemObject. You would not be using Notepad at all. I probably have this overly coded, but here it is anyway.
Code:
Sub BringText()
Dim fso As Scripting.FileSystemObject
Dim ts As Scripting.TextStream
Dim strIn As String

Set fso = New Scripting.FileSystemObject
Set ts = fso.OpenTextFile("c:\gerry\test2.txt")
strIn = ts.ReadAll

Worksheets("Sheet1").Range("A1").Value = strIn
Set ts = Nothing
Set fso = Nothing
End Sub

Gerry
See my Paintings and Sculpture
 
Thanks. But I've never put code in a spreadsheet before. How I do this?
 
What do you actually want to do with the text file?
create a new worksheet?
add it to an existing worksheet?
create a new file?
do you want to break the txt file into columns?

etc.
 
can you post a short example - along with a brief explanation of the whole process you are trying to accomplish?
 
You put the code in the Sheet1 module - assuming the Sheet name IS Sheet1.

pbrodsky's question are extremely valid. My code offering is based on trying to bring the text (and rememeber it will bring in only text) and putting that text into a cell. However, it does bring it in as a string - actually a dump from the clipboard. If you specify exactly what you want to happen, perhaps we can clear things up.

Please state EXACTLY what you want to do. Do not skip any steps. Do not assume we can read your mind and know what it is you are doing. Move through everything in the EXACT sequence you want things to go.

Gerry
See my Paintings and Sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top