如何在特定工作簿前显示EditRef控件?

时间:2017-05-24 00:24:33

标签: excel vba excel-vba

我有一个代码,它曾经在Excel 2010中运行得很好。我最近迁移到Excel 2013,它开始行为不端。代码试图打开一个工作簿,如果开放成功,它会显示一个带有一些RefEdit控件的useform。

Sub SetAddressess()
    This program opens the first file path indicated by MacroFolderOffice2010 and ask for the user to select
    the cells with all the necessary information to data reduction

    Dim FirstSamplePath As Range
    Dim WorkbookOpened As Workbook 'Name of the workbook opened

    If SamList_Sh Is Nothing Then
        Call PublicVariables
    End If

    If Len(SamList_Sh.Range(SamList_FilePath & SamList_FirstLine).Value) <> 0 Or Len(SamList_Sh.Range(SamList_FilePath & SamList_FirstLine).End(xlDown).Value) <> 0 Then
        Set AllSamplesPath = SamList_Sh.Range(SamList_FilePath & SamList_FirstLine, SamList_Sh.Range(SamList_FilePath & SamList_FirstLine).End(xlDown))
    Else
        Call MacroFolderOffice2010
            Set AllSamplesPath = SamList_Sh.Range(SamList_FilePath & SamList_FirstLine, SamList_Sh.Range(SamList_FilePath & SamList_FirstLine).End(xlDown))
    End If

    Set FirstSamplePath = AllSamplesPath.Item(1)

    If Len(FirstSamplePath.Value) = 0 Then
        MsgBox "There is no samples in SamList sheet. SetAddressess procedure.", vbOKOnly
        End
    End If

    On Error Resume Next

    ScreenUpd = Application.ScreenUpdating
        If ScreenUpd = False Then Application.ScreenUpdating = True

           Set WorkbookOpened = Workbooks.Open(FileName:=FirstSamplePath)

            If Err.Number <> 0 Then
                MsgBox MissingFile1 & FirstSamplePath & MissingFile2 & " - " & "SetAddressess procedure"
                    Call UpdateFilesAddresses
                        Call UnloadAll
                            End
        End If
    On Error GoTo 0

    Box4_Addresses.Show

        WorkbookOpened.Close

    Application.ScreenUpdating = ScreenUpd

End Sub

代码“Box4_Addresses.Show”后,窗口闪烁,用户窗体显示一秒钟,但“WorkbookOpened”和“Box4_Address”都不可见。我必须切换窗口才能看到它们。

使用以下代码初始化Box4_Addresses。

Private Sub UserForm_Initialize()

    If SampleName_UPb Is Nothing Then
        Call PublicVariables
    End If

    'Page Address controls
    Set Box4_Addresses_RawHg202 = Box4_Addresses.RefEdit1_202
    Set Box4_Addresses_RawPb204 = Box4_Addresses.RefEdit2_204
    Set Box4_Addresses_RawPb206 = Box4_Addresses.RefEdit3_206
    Set Box4_Addresses_RawPb207 = Box4_Addresses.RefEdit4_207
    Set Box4_Addresses_RawPb208 = Box4_Addresses.RefEdit20_208
    Set Box4_Addresses_RawTh232 = Box4_Addresses.RefEdit5_232
    Set Box4_Addresses_RawU238 = Box4_Addresses.RefEdit6_238
    Set Box4_Addresses_RawHg202Header = Box4_Addresses.RefEdit7_202Header
    Set Box4_Addresses_RawPb204Header = Box4_Addresses.RefEdit8_204Header
    Set Box4_Addresses_RawPb206Header = Box4_Addresses.RefEdit9_206Header
    Set Box4_Addresses_RawPb207Header = Box4_Addresses.RefEdit10_207Header
    Set Box4_Addresses_RawPb208Header = Box4_Addresses.RefEdit21_208Header
    Set Box4_Addresses_RawTh232Header = Box4_Addresses.RefEdit11_232Header
    Set Box4_Addresses_RawU238Header = Box4_Addresses.RefEdit12_238Header
    Set Box4_Addresses_RawCyclesTime = Box4_Addresses.RefEdit15_CyclesTime
    Set Box4_Addresses_RawAnalysisDate = Box4_Addresses.RefEdit22_AnalysisDate
    Set Box4_Addresses_RawNumCycles_Each_Sample = Box4_Addresses.RefEdit23_Num_Cycles

End Sub

调用“SampleName_UPb”只是为了检查是否设置了这个公共变量。我已经检查过它是否在代码执行期间没有设置,所以我认为问题与可能执行的程序“PublicVariables”无关。有什么建议吗?

0 个答案:

没有答案