Hi All,
I currently use the below code to allow users to attach documents (Normally Excel) to the current sheet.
When the Excel documents are embedded, they automatically open in the background. Is there a way of closing them? Currently, we embed the document, then close the master file and reopen it again. Could I add anything to the code to close the file as soon as it's embedded whilst keeping the master file open?
Thanks
In Advance
I currently use the below code to allow users to attach documents (Normally Excel) to the current sheet.
When the Excel documents are embedded, they automatically open in the background. Is there a way of closing them? Currently, we embed the document, then close the master file and reopen it again. Could I add anything to the code to close the file as soon as it's embedded whilst keeping the master file open?
Thanks
In Advance
VBA Code:
Private Sub CommandButton1_Click()
Sheet1.Unprotect ("passwordhere")
Set Rng = Range("F8")
Rng.RowHeight = 7.8
On Error Resume Next
fpath = Application.GetOpenFilename("All Files,*.*", Title:="Select file", MultiSelect:=True)
For i = 1 To UBound(fpath)
Rng.Select
Rng.ColumnWidth = 8.11
ActiveSheet.OLEObjects.Add _
Filename:=fpath(i), _
Link:=False, _
DisplayAsIcon:=True, _
IconFileName:="excel.exe", _
IconIndex:=0, _
IconLabel:=extractFileName(fpath(i))
ActiveSheet.OLEObjects.Locked = False
Set Rng = Rng.Offset(0, 1)
Next i
Sheet1.Range("H5").Value = "1"
Sheet1.Protect ("passwordhere")
End Sub
Public Function extractFileName(filePath) 'Used in code for attaching raw file
For i = Len(filePath) To 1 Step -1
If Mid(filePath, i, 1) = "\" Then
extractFileName = Mid(filePath, i + 1, Len(filePath) - i + 1)
Exit Function
End If
Next
End Function