Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-02-2017, 03:40 PM
jeddell jeddell is offline Opening a doc template - an Add-in Error Windows 10 Opening a doc template - an Add-in Error Office 2016
Novice
Opening a doc template - an Add-in Error
 
Join Date: Oct 2017
Posts: 3
jeddell is on a distinguished road
Default Opening a doc template - an Add-in Error

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.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error message when opening any template spiff1116 Word 6 11-04-2013 04:44 PM
Template "File In Use" when opening 2 documents based on the same template wendt Word 5 12-15-2009 12:37 AM
Error opening word from a doc. Davem501 Word 0 12-01-2009 02:10 AM
Error when opening .vcf files thorgal67 Outlook 0 04-06-2009 04:54 AM
Outlook XP *.msg opening error msg slmka Outlook 0 06-27-2007 09:00 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft