2014-09-25 94 views
0

我的宏在Excel 2010中工作得很好,但在2013年,我在激活vba中的工作簿方面遇到了一个主要问题,并且比选中某个工作表时选择了+单元格时我可以填写数据,但是当按回车或箭头键,数据被设置为我的文件的第一个可见页面。 当我激活另一个工作簿时,会发生这种情况,但在同一工作簿中,当我选择某个工作表时,输入的数据将转到第一张工作表.​​..从Excel 2010到2013的变化会发生什么?在excel 2013中激活工作表的问题

这是我使用的代码:

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

当我填写在V5的值和输入的值消失并在第一页显示了对V5 ...居多。

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

希望有人有答案。

+0

当你激活你的工作簿时,它会在你去年你在那里它的时候最后一个工作表。因此,您还需要将想要的工作表制作为活动工作表。否则你最终会在错误的页面上写东西。仍然会在您想要的页面中选择V5,但您不会在该页面上显示您的代码。尽管如此,我建议不要使用激活或选择。您可能还希望通过在代码开始处添加application.enableevents = false来禁用事件,并在最后重置为true。 – 2014-09-26 15:53:26

回答

0

做处理顺序:

Sub hfjsdfh() 
    Workbooks(MachineInspectieLijst & ".xlsm").Activate 
    Worksheets(MachineInspectieLijst).Select 
    Range("V5").Select 
End Sub 
0
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