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
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,086
Messages
5,570,136
Members
412,305
Latest member
Mozz
Top