Reading in data from a text file into excel macro

Shalih

New Member
Joined
Mar 2, 2011
Messages
16
Hi,

I need to read a data into an excel macro. I have the macro ready which can process once if the data is read in. the text file will have only one line of data (of 4 characters). The location of this text file is also hard coded. All i want is to read the data from the text file to be provided as input to the other macro's.:confused:
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hello Andrew,
Thanks for the quick response! But i still face error 52 and it points to [Open "F:\AAA\BBB\CCC\DDD\EEE\FFF\shalih.txt" For Input As #myName3]

My Code looks like:
[
Dim myFile As String
Dim myDir As String
Dim myName0 As String
Dim myName1 As String
Dim myName2 As String
Dim myName3 As Integer
Dim myName4 As String
Open "F:\AAA\BBB\CCC\DDD\EEE\FFF\shalih.txt" For Input As #myName3
Input #myName3, ShortText
Close #myName3
myName3 = ShortText
myDir = "TEXT;F:\AAA\BBB\CCC\DDD\EEE\FFF\"
myName0 = "D3_I_AAA-500-BCKUPTIME-"
myName1 = Year(Date)
myName2 = myName0 & myName1
'myName3 = Application.InputBox("Enter MMDD Filename", Type:=2)
myName4 = ".txt"
myName5 = myName3 & myName4
myName6 = myName2 & myName5
myFile = myDir & myName6


All i wanted is to pass the value from shalih.txt to the variable myName3
 
Upvote 0
You haven't assigned a value to myName3 and you can only use that variable once. Try replacing:

Code:
Open "F:\AAA\BBB\CCC\DDD\EEE\FFF\shalih.txt" For Input As #myName3
Input #myName3, ShortText
Close #myName3

with:

Code:
Dim FileNum As Integer
FileNum = FreeFile
Open "F:\AAA\BBB\CCC\DDD\EEE\FFF\shalih.txt" For Input As #FileNum
Line Input #FileNum, ShortText
Close #FileNum
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top