2014-09-25 90 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