Given you are learning you would do it something like this
Note that the code tests for the filepath being valid
your followup question
[b2] = "='" & strPath & "[" & strFile & "]" & strSht & "'!" & strCell
[b2].Copy [b3:com/tag/b4">b4]
original
Sub Test()
Dim strPath As String
Dim strFile As String
Dim strSht As String
Dim strCell As String
strSht = "Sheet2"
strCell = "A1"
strPath = "C:\temp\"
strFile = "test.xlsx"
If Len(Dir(strPath & strFile)) > 0 Then
[b2] = "='" & strPath & "[" & strFile & "]" & strSht & "'!" & strCell
Else
MsgBox "invalid file", vbCritical
End If
End Sub
manpreet
Best Answer
2 years ago
I'm right now learning VBA in excel by myself. As we know in excel we can put a file directory in a function to link one value in a file to another. Say for example when in a cell we can do this
How can I put this into a VBA script? Ultimately how can I pre-define "directory", "filename", "sheetname" and even cell position say something like