VBA File path

floggingmolly

Board Regular
Joined
Sep 14, 2019
Messages
167
Office Version
  1. 365
Platform
  1. Windows
I have a workbook has a code which loads the path for word templates. It works, but it gives the specific path like C:\User\Me\Mywordtemplates\template1.docx. If the workbook is moved or someone elses uses it, then the template can't be found. The templates are in the same file as the workbook, so I would like to be able to load that filepath then the template name. Below is the code if anyone can help i would appreciate it.

Code:
Sub AddWordTemplate()
Dim WordTempLoc As FileDialog
Dim FirstRow As Long
Set WordTempLoc = Application.FileDialog(msoFileDialogFilePicker)
FirstRow = Sheet2.Range("E99999").End(xlUp).Row + 1 'First Available Row
With WordTempLoc
    .Title = "Select Word file to attach"
    .Filters.Add "Word Type Files", "*.docx,*.doc", 1
    If .Show <> -1 Then GoTo NoSelection
    Sheet2.Range("E" & FirstRow).Value = Dir(.SelectedItems(1)) 'Document Name
    Sheet2.Range("F" & FirstRow).Value = .SelectedItems(1) 'Document Pathway
End With
NoSelection:
End Sub
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
If you mean the templates are in the same folder as the workbook then you can use ThisWorkbook.Path & "\" to get the path
 
Upvote 0
I tried editing the line of code that gives the path but it didnt work. I cant get this line to work using the activeworkbook path

Sheet2.Range("F" & FirstRow).Value = .SelectedItems(1) 'Document Pathway
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,545
Members
449,317
Latest member
chingiloum

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top