2017-06-14 38 views
0

我想通過Excel以外的VBscript從Excel工作簿中獲取信息。我可以找到工作表數據。現在我想從用戶窗體上的用戶窗體和對象獲取信息。我嘗試了下面的代碼,它在msgbox行上給出了一個錯誤。與excel以外的excel對象通信

感謝, 凱文

Dim oExcel 
Dim oWb 
Dim oSheet 

Set oExcel = CreateObject("Excel.Application") 
Set oWb = oExcel.WorkBooks.Open("C:\KAA\KAA.XLSM") 

msgbox oWb.UserForm1.height 

oWb.Close 
Set oExcel = Nothing 
Set oWb = Nothing 

回答

0

要訪問程序對象,你需要訪問的工作簿的VBProject

MsgBox oWb.VBProject.VBComponents("UserForm1").Name 
MsgBox oWb.VBProject.VBComponents("UserForm1").Designer.InsideHeight 

但在此之前,你需要(對自己的責任),以將安全設置爲信任對VBA項目對象模型

File -> Options -> Trust Center -> Trust Center Settings -> Trust Access to the VBA project object model.