S
Steve
Hi all. I have the below code to open the dialogue box to prompt the user to open a data file (a .csv file with only one sheet - Sheet1). I think I have that file path read into a variable. Now I need to write a formula into the original file against the data in the newly opened data file. The data file path and name will change, so it needs to be variable based on thefile the user selects. How can I incorporate the path of the data file into the formula in the master file? Thanks!
Sub Main()
Dim Filter As String, Title As String
Dim FilterIndex As Integer
Dim Source As Variant
Set Master = ThisWorkbook
Filter = "Excel Files (*.xls),*.xls," & _
"Text Files (*.txt),*.txt," & _
"All Files (*.*),*.*"
FilterIndex = 3
Title = "Select the Data Source File"
ChDrive ("C")
ChDir ("C:\")
With Application
Source = .GetOpenFilename(Filter, FilterIndex, Title)
' Reset Start Drive/Path
ChDrive (Left(.DefaultFilePath, 1))
ChDir (.DefaultFilePath)
End With
If Source = False Then
Exit Sub
End If
Workbooks.Open Source
Ticket.Activate
Set frng = Range("A1")
With frng
'--------------------------------------------------------------------------
'THIS IS THE PART I CANE SEEM TO FIGURE OUT
..Formula = "='" & Source & "Sheet1!B5"
'--------------------------------------------------------------------------
End With
Sub Main()
Dim Filter As String, Title As String
Dim FilterIndex As Integer
Dim Source As Variant
Set Master = ThisWorkbook
Filter = "Excel Files (*.xls),*.xls," & _
"Text Files (*.txt),*.txt," & _
"All Files (*.*),*.*"
FilterIndex = 3
Title = "Select the Data Source File"
ChDrive ("C")
ChDir ("C:\")
With Application
Source = .GetOpenFilename(Filter, FilterIndex, Title)
' Reset Start Drive/Path
ChDrive (Left(.DefaultFilePath, 1))
ChDir (.DefaultFilePath)
End With
If Source = False Then
Exit Sub
End If
Workbooks.Open Source
Ticket.Activate
Set frng = Range("A1")
With frng
'--------------------------------------------------------------------------
'THIS IS THE PART I CANE SEEM TO FIGURE OUT
..Formula = "='" & Source & "Sheet1!B5"
'--------------------------------------------------------------------------
End With