Anthony's VBA Forum Index Anthony's VBA Forum
Where the knowledge is shared
Menu
 Anthony's VBA Forum IndexHome Page
 Anthony's VBA Forum IndexForum Index
FAQFAQ
MemberlistMemberlist
UsergroupsUsergroups
RegisterRegister
ProfileProfile
Log in to check your private messagesMessages
Log inLogin/Out

Quick Search

Advanced Search

Links
Consulting
Products

Who's Online
[ Administrator ]
[ Moderator ]


User input file to link cells in Excel

 
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA
View previous topic :: View next topic  
Author Message
AntionesEquation



Joined: 07 Jul 2009
Posts: 2
Location: Globe AZ

PostPosted: Thu Jul 09, 2009 10:32 pm    Post subject: User input file to link cells in Excel Reply with quote

I am trying to reference cells in Excel to Excel file on a NAS. I need to take the file names the user enters in and put them cell to have those equal the values. Is this the best way of doing this? I don't know I am pretty new to this.

[code]
Sub button2click()
'This macro gets the file names of the daily reports files
Dim Filt As String
Dim FilterIndex As Integer
Dim fileName As Variant
Dim Title As String
Dim i As Integer
Dim Msg As String
Dim add As String

Flit = "Text Files (*.txt), *.txt" & _
"Excel Files (.xls), *.xls" & _
"All Files (*.*), *.*"

FilterIndex = 5

Title = "Select a File to Import"

fileName = Application.GetOpenFilename(Filt, FilterIndex, Title, , True)

If Not IsArray(fileName) Then
MsgBox "No file was selcted."
Exit Sub
End If

For i = LBound(fileName) To UBound(fileName)
Msg = Msg & fileName(i) & vbCrLf
Next i
MsgBox "You selected:" & vbCrLf & Msg

For j = LBound(fileName) To UBound(fileName)
Worksheets("Sheet1").Cells(j + 1, 2).Value = fileName(j)
Next


End Sub
[/code]

the value the last for loop does is copy string values into cells. If my file was N:\daily\report.xls and I wanted to use the value on D5 of sheet one of this file then in excel I would type, = '=N:\daily\[report.xls]'!D5. How can I reference this with user selected files?

I am new to forums, and VBA
Back to top
View user's profile Send private message
AntionesEquation



Joined: 07 Jul 2009
Posts: 2
Location: Globe AZ

PostPosted: Tue Jul 14, 2009 10:30 pm    Post subject: a work around Reply with quote

I can reference the files if I keep the files in the same directory as the excel file that is running the macro. I just wish there was some way of getting references to the file on the NAS
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group