excel-vba

Query div element by class name using Excel VBA

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 11:06:11
问题 I'm trying to get the data to Excel of a div element with a specific class name, like: <div class="myClass"> <span>Text1</span> <span>Text2</span> </div> My VBA code: Sub GetData() Dim oHtml As HTMLDocument Dim oElement As Object Set oHtml = New HTMLDocument With CreateObject("WINHTTP.WinHTTPRequest.5.1") .Open "GET", "http://www.example.com/", False .send oHtml.body.innerHTML = .responseText End With For Each oElement In oHtml.getElementsByClassName("myClass") Debug.Print oElement.Children(0

If IsError in VBA?

喜夏-厌秋 提交于 2020-01-11 10:55:07
问题 Is it possible to use something with similar functionality as Iferror(value, value_if_error) or Iserror(value) in VBA? I tried to write: If IsError(Cells(i, c) / curr) Then 'CODE BLOCK 1 else 'CODE BLOCK 2 end if But VBA tells me that I have division by zero error when it tries to run the if-statement. It throws me into debug. But this is just the type of thing I want to trigger CODE BLOCK 1! 回答1: The usual way to handle this would be i = 0 On Error Resume Next n = 1 / i If Err.Number <> 0

Dictionary doesn't display Items for certain Key (Numeric value)

浪子不回头ぞ 提交于 2020-01-11 10:29:28
问题 This is a Long one, but stay with me ... I have a Dictionary that saves "PO" as Key and "SO" as Items (there can be cases that a certain "PO" has multiple "SO". My Excel data in a worksheet, where the Dictionary get's his values looks like this: The code for populating the Dictionary (working) looks like this: Option Explicit Const OrdersDBShtName As String = "Orders_DB" Public OrdersDBSht As Worksheet Public LastSORow As Long Public PODict As Object ' Public Dictionay for PO#, and keep SO

Subscript out of range error when trying to copy Excel charts to Power Point presentation

喜你入骨 提交于 2020-01-11 09:53:11
问题 I am trying to copy charts from excel to PPT in a PPT macro using a function. Though, when I try to run the function it says "Subscript out of range" on the line indicated below and I am really confused why. Public dlgOpen As FileDialog Public folder As String Public excelApp As Object Public xlWorkBook As Object Public xlWorkBook2 As Object Public PPT As Presentation Public Name1 As String Public Name2 As String Public rng1 As Range Public rng2 As Range Dim NamedRange As Range Public Sub

paste special values in vba

独自空忆成欢 提交于 2020-01-11 09:52:15
问题 I am working on a small project which requires me to copy and paste certain columns if I detect "true" in the row. I am trying to paste these selected columns onto a different sheet and I want to paste only their values not the formulas. This is what I have so far and I am getting an error with the paste special feature. Please help. ' CopyIfTrue() Dim Col As Range, Cell As Excel.Range, RowCount As Integer Dim nysheet As Worksheet Set nysheet = Sheets.Add() nysheet.Name = "T1" Sheets(

excel: vba type mismatch comparing dates

巧了我就是萌 提交于 2020-01-11 09:45:32
问题 I'm trying to make a comparison between years from two dates (in different columns) and the current year date. If the year is the same then it should write on the corresponding row at column 13 the word "ATUAL", if the year is different then it should write nothing. This is what I've tried so far. Sub CopyColumn2() Dim i As Long Dim j As Long Dim lastrow As Long Dim ws1 As Worksheet Dim ws2 As Worksheet Dim wbk As Workbook Dim wb As Worksheet Set wbk = Workbooks.Open("I:\CGP\DEOPEX\01 -

Speeding up VBA Code to Run Faster

一笑奈何 提交于 2020-01-11 09:39:04
问题 I have an Excel Workbook where the user imports a text file by the click of a button. My code works exactly as I need it to but it is extremely slow when filling in column H, Reading Date. Here is what my Excel Workbook looks like when the text file has been imported to the excel sheet: Here is my code: Sub Import_Textfiles() Dim fName As String, LastRow As Integer Worksheets("Data Importation Sheet").Activate LastRow = Range("A" & Rows.Count).End(xlUp).Row + 1 ' Finds the first blank row to

VBA: Why isn't variable working in named range?

白昼怎懂夜的黑 提交于 2020-01-11 09:35:26
问题 This is part of a larger code, but this snippet isn't working. I'm trying to just set two cells equal to each other, but it's not working. When I use the .Range("v1_copy"), the code runs, but when I name that range and place it as a variable (myCopyRange), the code doesn't run and I get the error: Compile error: Method or data member not found. Any help would be appreciated! Sub copy_paste_test() Dim myCopyRange As Range Dim myPasteRange As Range Dim myWS1 As Worksheet Dim myWS2 As Worksheet

url checker VBA, when redirected, show redirected url

依然范特西╮ 提交于 2020-01-11 09:34:28
问题 I'm quite new to EXCEL VBA's and I'm kinda stuck finding a way to create a MACRO that shows whether a url is still active (200 ok), or may be redirected, and if so, I want to know to what URL. And when it's not working at all, then return the right code with the reason the URL isn't working. So at the moment I have a script that actually works but it doesn't return the url to which an url is redirected to. It only returns (200 OK) when an url is still active, or the url that the original url

Saving Excel data as csv with VBA - removing blank rows at end of file to save

坚强是说给别人听的谎言 提交于 2020-01-11 09:32:31
问题 I am creating a set of csv files in VBA. My script is creating the data set I need, but the number of rows differs in multiple iterations of the loop. For instance, for i=2, I have 100,000 rows, but for i=3, I have 22,000 rows. The problem is that when Excel saves these separate csv files, it does not truncate the space at the end. This leaves 78,000 blank rows at the end of the file, which is an issue given that I need about 2,000 files to be generated, each several megabytes large. (I have