I have a Word macro that isn't working and I hope someone can help me with it. It's probably something simple I am overlooking but I have been staring at it too long to see it.
I have a Word 2013 doc.dotm file that has a customUI with iRibbonControl that launches several different custom macros. I have all macros working except for one. The macro needs to create a new Word document based on a custom template that is in a shared folder on the network. There are multiple custom templates in the repository so the user needs the ability to select the correct custom template when launching the macro. I am using the Documents.Add Template:="doc.dotx" Method to create the new document. The method works perfectly if I specify the full path and document name within the quotes.
But I need to pass a variable to the Documents.Add method so I tried the following code. I can make the file selection dialog come up correctly but after selecting a file and clicking ok, VBA reports that the file couldn't be found and it is blank where the incorrect path would normally be referenced in the error message. I'm only using MS Word VBA Editor and I can't step through and see the variable values since the code is launched by an iRibbonControl, not a standard macro.
Can someone review my code and see if I'm missing something obvious? Thanks in advance for your help!!
Full Disclosure: I got the code snippet for the FileDialog function from http://analystcave.com/vba-application-filedialog-select-file/
' This line works perfectly.
' Documents.Add Template:="Path+doc.dotx"
'This section prompts for a file selection but doesn't
'pass the result to the Documents.Add method.
Dim fDialog As FileDialog, result As Integer
Set fDialog = Application.FileDialog(mso
fDialog.AllowMultiSelect = False
fDialog.Title = "Select a Template"
fDialog.InitialFileName = "PathtoTemplates"
fDialog.Filters.Add "Word Template Files", "*.dotx"
'Show the dialog. -1 means success
If fDialog.Show = -1 Then