none
Userform disappear after calling FSO and opening a document --> remaining code stop executing RRS feed

  • Question

  • Hello,

    I have a Word macro composed of several userforms. All userforms have a "Browse" button to select an .rtf file. However, this button is only the first part of a process to work on the file.

    The code used to execute fine, but not, every single time I select a file, the file opens, but the userform disappear and the remaining of the code does not execute.

    I am working under W10 and O16.

    The code is as follows:

    Public MyPath as String
    
    Private Sub Btn_GetFile_Click()
    
        Dim Fso As FileDialog
    
        If MyPath = vbNullString Then
            MyPath = Environ("SystemDrive") & Environ("HOMEPATH") & "\Documents\"
        End If
        
        Set Fso = Application.FileDialog(msoFileDialogFilePicker)
        
        Application.ScreenUpdating = False
        
        With Fso
            .Filters.Clear
            .InitialFileName = MyBasicPath
            .AllowMultiSelect = False
            .Title = "Select the DVX External view to import"
            .Filters.Add "RTF files", "*.rtf"
            If .Show = True Then
                Set WorkDocument = Documents.Open(.SelectedItems(1), ReadOnly:=False, Visible:=False)
                'Code to check file validity based on document content
                'This does not execute. ANY CODE after the SET line does not execute. 
                'To check this, I put a break point, but to no avail
            End If
        End With
    
    End Sub

    Thank you in advance for any solution to sort this weird issue.

    As I said, this used to work fine, but not anymore.

    The issue is the same whether the document visibility is set to True or False.

    Kind regards,

    Athlagan



    • Edited by Athlagan Wednesday, August 15, 2018 11:25 PM
    Wednesday, August 15, 2018 11:14 PM

All replies

  • works for me, but I had to made some changes:

    declare the variable: Dim WorkDocument As Word.Document

    after this the document will be opend on the background, to bring it visible, try visible = true

    Thursday, August 16, 2018 8:44 AM
  • Hello Wouter,

    Thank you for your reply and your suggestion.

    WorkDocument is a public variable.

    I tried changing it to

    Public WorkDocument As Word.Document

    but this did not change the outcome. I even modified the code to bypass the FSO and just open a specific document within the code, and the same occurs. As soon as the

    Set WorkDOcument = Documents.Open(SpecifiFileNameFullPath)

    is executed, the rest of the code is not (I put a break point on the following line of code and it never reaches that point) and the userform disappear. It doesn't matter whether the visible option of the document is set to True or False, the behaviour remains the same.

    In other forums (see https://stackoverflow.com/questions/11422114/vba-form-disappearing), they are speaking about this issue, but all the fixes suggested do not work.

    I am absolutely puzzled.


    • Edited by Athlagan Friday, August 17, 2018 12:55 PM
    Friday, August 17, 2018 12:54 PM
  • Hello,

    it's strange. 

    Maybe you could try to bypass word an try to open you path through shell ?

    https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/shell-function

    (but than you loose the power to do anything with the word document...)

    Friday, August 17, 2018 1:01 PM
  • Hello,

    Thank you for your prompt reply.

    As the macro is Word based, I find it strange to shell WinWord from Word. Also, the code executes fine if I call on the current document (userform does not disappear and the code executes normally). The WorkDocument needs to be edited (purpose of the macro).

    I just checked on another macro I wrote (a few year ago and which worked fine for all that time, but that I haven't used in a while) and the same occurs. On opening ANY Word document, the userform disappears and the remaining code is not executed.

    This is a serious annoyance.

    I am going to try to repair my Office installation to see if this sorts the issue.

    Friday, August 17, 2018 1:14 PM
  • Thank you all.

    After repairing Office 2016 (complete repair!), this issue is sorted, now my userforms remain visible and the code executes after opening other documents.

    :-)

    • Marked as answer by Athlagan Saturday, August 18, 2018 3:15 PM
    • Unmarked as answer by Athlagan Tuesday, September 4, 2018 2:50 AM
    Friday, August 17, 2018 4:14 PM
  • The problem came back the following day, and still remains.

    I have tried anything and everything I could think of, but to no avail. The probelm persists.

    Any help or comment, particularly from Microsoft would be appreciated.

    Kind regards

    Tuesday, September 4, 2018 2:52 AM