請問用VB開啟EXCEL做搜尋一直出現"未設定物件變數或WITH變數"
請問是那裏出錯了!
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim L_OPseq As String
Dim L_Priorit As String
Dim L_PN As String
Dim L_Description As String
Dim L_Brand As String
Dim L_BrandPN As String

Set xlApp = CreateObject("excel.application")
Set xlbook = xlApp.Workbooks.Open(filename)
Set xlsheet = xlbook.Worksheets(1)

''開啟檔案設定

  Windows(P).Activate

With xlsheet  ''開啟檔案
  
  
  
  DoEvents
  
  '進行搜尋動作

   Cells.Find(What:=fox_PN, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, MatchByte:=False, SearchFormat:=False).Activate
  Cells.FindNext(After:=ActiveCell).Activate
  
  
   ActiveCell.Select
   Selection.End(xlToLeft).Select
   L_OPseq = ActiveCell.Offset(0, 0).Range("A1")
   L_Priorit = ActiveCell.Offset(0, 0).Range("D1")
   L_PN = ActiveCell.Offset(0, 0).Range("B1")
   L_Description = ActiveCell.Offset(0, 0).Range("C1")
   L_Brand = ActiveCell.Offset(0, 0).Range("E1")
   L_BrandPN = ActiveCell.Offset(0, 0).Range("F1")
  
  
   List2.AddItem L_OPseq & "_" & L_Priorit & "_" & L_PN & "_" & L_Description & "_" & L_Brand & "_" & L_BrandPN
  
 
     
  
  End With
創作者介紹
創作者 vbqa 的頭像
vbqa

小吳 VBQA 程式設計討論

vbqa 發表在 痞客邦 留言(5) 人氣()