SAY討論區

標題: Excel Automation 一問(vb.net to open a locked excel file) [打印本頁]

作者: frankyhui    時間: 2012-5-12 02:19:27     標題: Excel Automation 一問(vb.net to open a locked excel file)

Dim vbProj As Object
  Dim sPassword As String

  On Error GoTo ErrorHandler

  sPassword = sVBEPW

  'Check to see if VBA project is already unlocked
  If objExcelApp.VBE.ActiveVBProject.Protection < 1 Then Exit Function

  'SendKeys is the only way
  If sPassword = ^^ Or sPassword = ++ Then
    sPassword =
    Exit Function
  ElseIf Right(sPassword, 2) = ^^ Or Right(sPassword, 2) = ++ Then
    sPassword =
    Exit Function
  Else

    With objExcelApp
      .SendKeys(%{F11}, True)
      .SendKeys(^r, True)
      .SendKeys({DOWN}, True)
      .SendKeys(sPassword, True)
      .SendKeys(~, True)
    End With

    'objExcelApp..SendKeys(sPassword & ~~ & {ESC})
    'objExcelApp.VBE.CommandBars(1).FindControl(Id:=2578, Recursive:=True).Execute()

  End If

  'Not the right password
  'If objExcelApp.VBE.ActiveVBProject.Protection = 1 Then
  'objExcelApp.Application.SendKeys(%{F11}, True)
  'UnprotectVBProject = False
  'Exit Function
  'End If

  UnprotectVBProject = True

End Sub

'May i know why this not working .... million thanks
作者: frankyhui    時間: 2012-5-14 13:04:21

有才的不在少數啊
作者: HOTSTUDIO阿蚊    時間: 2012-5-14 13:04:21

快站沙發,不知道有沒有成功




歡迎光臨 SAY討論區 (http://say.go2tutor.com/) Powered by Discuz! X2