Place an excel file in Unix and access it from an excel macro

Posted on 2010-08-30
Medium Priority
Last Modified: 2012-05-10

I want to place an .txt in Unix and to read the file from an excel macro code.

The txt file just have the database credentials like,
User Id=xxx
Initial catlog=xxx

Can someone help me ftp and read the data back
Question by:pnadakuditi
  • 2

Accepted Solution

AndrewSwingewood earned 2000 total points
ID: 33567180
You can use the following code to run a DOS script from a macro:

Sub downloadFTP()
Dim dRetVal As Variant
dRetVal = Shell("C:\download.bat", 1)
End Sub

The contents of download.bat should be the ftp command, i.e:

ftp -i -s:c:\script.dat yourunixbox

The contents of script.dat should be the ftp commands, ie.:

username 'user for ftp site
password 'password for ftp site
cd /path_to_file
lcd c:\
get file.txt

You will then be able to read the text file from the local disk.  If you want the code to be portable, you can use excel to write download.bat and script.dat prior to executing the shell command.

Hopefully this is what you need

Assisted Solution

AndrewSwingewood earned 2000 total points
ID: 33615529
I have just re-read your question and realised that you also need to know how to read the file into VBA.  This can be done using code similar to:

Sub Read_text_File()

Dim oFSO As New FileSystemObject
Dim oFS

Set oFS = oFSO.OpenTextFile("c:\file.TXT")

Do Until oFS.AtEndOfStream
sText = oFS.ReadLine

End Sub


Author Comment

ID: 33844615
Dont want to close the question.. the above solution is hoping me good.. need to implement it and verify the results

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question