Hi,
Having issues writing the below and getting it to work. I want it to be able to use a cell in an excel document to determine which file needs to be picked up, it's currently opening the dialog box where I'd usually select the folder, but not selecting the relevant file automatically. The filepath is stored within cell D7 of C:\Morning Imports.xlsm
Any help is greatly appreciated
Having issues writing the below and getting it to work. I want it to be able to use a cell in an excel document to determine which file needs to be picked up, it's currently opening the dialog box where I'd usually select the folder, but not selecting the relevant file automatically. The filepath is stored within cell D7 of C:\Morning Imports.xlsm
Any help is greatly appreciated
Code:
Function ImportCancellationAuto()
Dim fd As Object, fileName As String
Dim varFile As Variant
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = New Excel.Application
With xlApp
Set xlWB = .Workbooks.Open("[COLOR=#2A2A2A][FONT='inherit']C:\[/FONT][/COLOR]Morning Imports.xlsm", , False)
Set xlSheet = xlWB.Worksheets("Sheet1")
End With
varFile = xlSheet.Range("D7")
Set fd = Application.FileDialog(3)
fd.AllowMultiSelect = False
If fd.Show = True Then
For Each varFile In fd.SelectedItems
DoCmd.TransferText acImportDelim, "OrderCancellation_Specification_2", "order_Cancellation", "varFile"
fileName = varFile
Next
Else
MsgBox "You have cancelled the import."
End If
End Sub