Help with my Code

Mgreencornerstone

Board Regular
Joined
Nov 23, 2005
Messages
116
I am currently using the code below to open a file and retrieve data, and I would like to pull the data up under a different sub. I have used
Sub getinfo()
FileOpenSub
[A1] = Account
End Sub

to attempt to pull up the "Account" text from the file but it did not work. I have about 10 different subs that would pull the data. I would like to streamline this as much as possible so i dont have to include the below sub in every other sub.
Code__________________________________________________________
Private Sub FileOpenSub()
Dim MyFile, Info, Account, AccountName, AccountLast, Filedir
Filedir = "File.log"
MyFile = Dir(Filedir) 'locates the file
If MyFile = "File.log" Then
Dim r As Integer
r = 0
Dim TextLine
Open Filedir For Input As #1
Do While Not EOF(1)
Input #1, TextLine
If r = 0 Then Info = TextLine
If r = 1 Then Account = TextLine
If r = 2 Then AccountName = TextLine
If r = 3 Then AccountLast= TextLine
r = r + 1
Loop
Close #1
End If
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi Mgreencornerstone,

If you mean that you would like to call FileOpenSub from other procedures (other than getinfo), and these procedures are located in different code modules, you should make the sub public, i.e.,

Public Sub FileOpenSub()

If FileOpenSub is located in an event code module (a worksheet, ThisWorkbook, or UserForm module) I recommend that you move it to a standard macro module.

Damon
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

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