【问题标题】:Problems activating worksheet in excel 2013在 excel 2013 中激活工作表时出现问题
【发布时间】:2014-09-25 16:57:54
【问题描述】:

我的宏在Excel 2010中的工作完美,但2013年,我在VBA中激活工作簿有一个主要问题,而不是选择某些工作表+单元格,我可以填写数据,但是按Enter或Arrow键时,请填写数据,但是按Enter键或箭头键时,请填写数据数据设置为我文件的第一个可见页面。 当我激活另一个工作簿时会发生这种情况,而且当我选择某个工作表时在同一个工作簿中,输入的数据将转到第一个工作表......从 excel 2010 到 2013 发生了什么变化??

这是我使用的代码:

Workbooks(MachineInspectieLijst & ".xlsm").Activate
Workbooks(MachineInspectieLijst & ".xlsm").Worksheets(MachineInspectieLijst).Range("V5").Select

当我在 V5 中填写一个值并输入时,该值会消失并显示在 V5 的第一页...大部分情况下。

当我在页面或工作簿之间手动切换时,它会起作用...我找不到任何答案。

希望有人知道答案。

【问题讨论】:

  • 当您激活您的工作簿时,它会进入您上次在那里的最后一张工作表中。因此,您还需要将所需的工作表设为您的活动表。否则你最终会在错误的页面上写东西。仍然会在您想要的页面中选择 V5,但您的代码不会出现在该页面上。尽管如此,我建议永远不要使用激活或选择。您可能还想通过在代码开头添加 application.enableevents=false 并在末尾重置为 true 来禁用事件。

标签: excel excel-2013 vba


【解决方案1】:

按顺序执行该过程:

Sub hfjsdfh()
    Workbooks(MachineInspectieLijst & ".xlsm").Activate
    Worksheets(MachineInspectieLijst).Select
    Range("V5").Select
End Sub

【讨论】:

    【解决方案2】:
    This is the actual sub, I tried your suggestion, but exactly the same...Indeed, it is like the second workbook is not really activated, but how to solve? has it to do with the userform who stays loaded? this one must stay loaded, as it contains lot of necessary information and is only unloaded at new start. Nevertheless, I tried to unload as test, but same problem. Can it be due to excel itself?
    
    Private Sub CmdGetInspectionList_Click()
    Dim thesentence As String
    Dim WB As Workbook
    Set WB = ThisWorkbook
    Dim WB2 As Workbook
    frmKlantSelectie.Hide
    Application.EnableEvents = False
    If Me.cboDocumentType.Value = "Sales Budget Quotation" Then
         MachineInspectieLijst = "Machines_Sales"
         WB.Worksheets("PreInspArticles").Range("J1") = "Sales"
    Else
         MachineInspectieLijst = Me.cboInspectieMachine.Value
    End If
    loginnaam = StrConv(WindowsUserName, vbUpperCase)
    thesentence = "C:\Users\" & loginnaam & "\Dropbox\2_Doc_Service\DATA\Pre_Inspection_Checklist\" &      MachineInspectieLijst & ".xlsm"
    
    'checken ofdat de file wel bestaat in de directory
     If Dir(thesentence) <> "" Then
         MsgBox "Machine Check list exists! Press 'OK' and file will be shown!"
    'Test to see if the file is open.
        If IsFileOpen(thesentence) Then
           Workbooks(MachineInspectieLijst & ".xlsm").Activate
        Else
     'Display a message stating the file is not in use.
        Set WB2 = Workbooks.Open(thesentence)
     End If
      Else
         MsgBox "No machine selected Or Check list not yet existing."
         frmKlantSelectie.Show
         Me.TxtInspectionList.SetFocus
      Exit Sub
      End If
        WB2.Worksheets(1).Range("V5").Select
        Application.EnableEvents = True
    
      End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 2015-07-06
      • 2019-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多