Чтобы улучшить повторяемость работы, я попытался получить доступ к веб-сайту, который используется в компании, с помощью VBA. Итак, я написал код на VBA. И я проверил, что это может быть доступ к обычному сайту, например google, ...

0
ahnsanghyuk 28 Дек 2020 в 05:29

1 ответ

Лучший ответ

Вы можете попробовать следующий код. Пожалуйста, прочтите комментарии. Я не могу больше сказать, потому что я не знаю страницу или html страницы.

Sub a()

'Use late binding for what you need
Dim ie As Object
Dim nodeInputData As Object
Dim url As String

  url = "https://www.google.com"
  
  'Use the windows GUID to initialize the Internet Explorer, if you
  'want to get access to a company page. This helps if there are
  'security rules you can't access over other ways of initializing IE
  'This don't work in most cases for pages in the "real" web
  'Read here for more infos:
  'https://blogs.msdn.microsoft.com/ieinternals/2011/08/03/default-integrity-level-and-automation/
  Set ie = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
  ie.Visible = True
  ie.navigate url
  'Waiting for the document to load
  Do Until ie.readyState = 4: DoEvents: Loop
  'If necessary, if there is dynamic content that must be loaded,
  'after the ie reports, loading was ready
  '(The last three values are: hours, minutes, seconds)
  Application.Wait (Now + TimeSerial(0, 0, 1))
  
  'I don't know your html. If you only want to click a button,
  'you don't need a varable
  'ie.document.getElementsByClassName("text")(0).Click
  'will do the same like
  Set nodeInputData = ie.document.getElementsByClassName("text")(0)
  nodeInputData.Click
  
  'A short explanation of getElementsByClassName() and getElementsByTagName():
  'Both methods create a node collection of all html elements that was found
  'by the creteria in the brackets. This is because there can be any number of
  'html elements with specified class names or tag names. If, for example,
  '3 html elements with the class name "Text" were found, a node collection
  'with three elements is created by getElementsByClassName("Text").
  'These have the indices 0 to 2, as in an array. The individual elements are
  'also addressed via these indices. They are indicated in round brackets.
End Sub
0
Zwenn 28 Дек 2020 в 13:20