Have you step debugged? Follow the code as it executes. See where it deviates from expected behavior. Fix. Repeat. Refer to link at bottom of my post for guidance on debugging techniques.
Have you set VBA reference to: Microsoft Office 12.0 Object Library ?
Need to use drive letter or UNC in file path: .InitialFileName = "C:\Template path\"
This works for me:
Code:
Sub SelectCopyOpenExcelFile()
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Dim strFrom As String, strTo As String
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Default path
.InitialFileName = "C:\Temp\"
'Not allow user to make multiple selections
.AllowMultiSelect = False
'Set the title of the dialog box.
.Title = "Select one file"
'Clear the current filters, and add our own.
.Filters.Clear
.Filters.Add "Excel Workbook", "*.xlsx"
If .Show = True Then
For Each varFile In .SelectedItems
strFrom = varFile
Next
End If
End With
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
'Default path
.InitialFileName = "C:\"
'Set the title of the dialog box.
.Title = "Select destination folder"
.Show
strTo = .SelectedItems(1) & Mid(strFrom, InStrRev(strFrom, "\") + IIf(Len(.SelectedItems(1)) = 3, 1, 0))
End With
CreateObject("Scripting.FileSystemObject").CopyFile strFrom, strTo, True
Application.FollowHyperlink strTo
End Sub