Hey everyone,
I have an add-in I use for my wok that has a suite of document templates and vba code to automate the specific layout and formating of the documents. Its used for writing technical data and making sure that they all look the same.
The add-in has been around for many years in our organisation and has been developed since Office 97 through to XP and in MS Word since Office 97. Im now using this add-in in Office 2016. On the whole it works fine, but im having a problem opening a document already created. I keep getting a custom error message. I found the code where the message is being generated, but Im not that good at troubleshooting this code. Can anyone take a look at this code and tell me if there is anything here that would stop it from working in MS Word 2016? Basically the error states that I havent selected a file, but the code does not give me a chance to select a file.
Code:
Public Function SelectFileOpenDialog(strInitDir As String, strTitle As String, strFilter As String) As String
Dim strTemp As String
Dim strTemp1 As String
Dim pathStr As String
Dim i As Long
Dim n As Long
Dim j As Long
Dim OFN As OPENFILENAME
Dim lReturn As Long
Dim strFilterString As String
Dim strFilename As String
OFN.lStructSize = Len(OFN)
strFilterString = Replace(strFilter, "|", Chr(0)) & Chr(0)
OFN.lpstrFilter = strFilterString
OFN.nFilterIndex = 1
OFN.lpstrFile = String(257, 0)
OFN.nMaxFile = Len(OFN.lpstrFile) - 1
OFN.lpstrFileTitle = OFN.lpstrFile
OFN.nMaxFileTitle = OFN.nMaxFile
OFN.lpstrInitialDir = strInitDir
OFN.lpstrTitle = strTitle
OFN.hwndOwner = GetActiveWindow()
OFN.flags = 0
lReturn = GetOpenFileName(OFN)
If lReturn = 0 Then
MsgBox "You didn't select any file"
strFilename = ""
Else
strFilename = Trim$(OFN.lpstrFile) ' copy the filename
End If
SelectFileOpenDialog = strFilename
End Function
Here's the getopenfilename code that seems to be returning nothing. This is one of the pieces that had to be declared ptrSafe as you can see
Code:
Public Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public gstrTypeSelected As String
Public gstrJITypeSelected As String
Private Type typToolbarNamePos
strName As String
lngPosition As Long
End Type
'array to store the user's toolbar settings
Public garPrevToobars() As typToolbarNamePos
'array to store the user's style settings
Public garPrevStyles() As String
Public Type typStyleName
strStyleNameGeneric As String
strStyleName97 As String
strStyleName2003 As String
bPromotable As Boolean
bDemotable As Boolean
End Type
Public garStyleNames() As typStyleName
if you need any other parts of this code to further analyse, I'm happy to provide
Thanks in advance.