View Single Post
 
Old 12-13-2018, 09:20 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

That would imply that either the path or filename is wrong. The following code should replace the function I previously supplied. In this one, we are dynamically working out the path to the Desktop rather than hard coding it (which will allow it to work on other machines). It also returns a message if the passed in file doesn't exist at that location.
Code:
Function InsertAFile(sFile As String)
  Dim sPath As String
  sPath = Environ("USERPROFILE") & "\Desktop\"
  If FileExists(sPath & sFile) Then
    Selection.InsertFile FileName:=sPath & sFile, ConfirmConversions:=False, Link:=False, Attachment:=False
    Selection.TypeBackspace
  Else
    MsgBox "File doesn't exist: " & vbCr & sPath & sFile, vbOKOnly, "Missing file"
  End If
End Function

Function FileExists(sFilePath As String) As Boolean
  Dim FSO As Object
  Set FSO = CreateObject("Scripting.FileSystemObject")
  FileExists = FSO.FileExists(sFilePath)
End Function
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote