vba

VBA code to select from an HTML drop down, using value rather than index

假装没事ソ 提交于 2021-02-04 19:35:09
问题 I'm fairly new to VBA and HTML. I am writing a VBA macro which navigates through a website, before filling in a web form. During navigation, the script needs to pick an option from a drop-down menu. I am currently using the following (no doubt awful, but functional) code, which finds the correct drop-down menu before selecting the option at index 2. Set dropOptions = HTMLDoc.getElementsByTagName("select") For Each op In dropOptions If op.getAttribute("name") = "tilastojakso" Then op.Focus op

Error in Hash Implementation in VBA - Runtime Error -2146232576 (80131700)

二次信任 提交于 2021-02-04 19:27:26
问题 I have implemented the hash method as suggested on the post: Does VBA has a Hash_HMAC This is my implementation: Public Function BASE64SHA1(ByVal sTextToHash As String) Dim asc As Object Dim enc As Object Dim TextToHash() As Byte Dim SharedSecretKey() As Byte Dim bytes() As Byte Set asc = CreateObject("System.Text.UTF8Encoding") Set enc = CreateObject("System.Security.Cryptography.HMACSHA1") TextToHash = asc.GetBytes_4(sTextToHash) SharedSecretKey = asc.GetBytes_4(sTextToHash) enc.Key =

Dynamic Autofill Destination

本秂侑毒 提交于 2021-02-04 19:22:05
问题 Need some help with this code: Dim numRows As Long numRows = Cells(Rows.Count, "A").End(xlUp).Row Selection.AutoFill Destination:=Range(Cells(1, 12), Cells(numRows, 12)), Type:=xlFillDefault The macro is supposed to fill column L with a formula. It works with files with multiple rows but ends with: Autofill method of Range class failed. For files with only one row. 回答1: Tips: Avoid the use of Selection . In your code, the selection may not be the "selection" you think it is ;) You may want to

VBA Excel - Working with multiple textboxes with the same code

…衆ロ難τιáo~ 提交于 2021-02-04 16:38:06
问题 So I'm new to this area. I just want to ask if how can I minimize the use of the code below since I do have 13 textboxes with the same code. Is there a short way to do this? Here's the UserForm that I'm using -> Here's the code Private Sub tb_mtb_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Not IsNumeric(tb_mtb.Value) Then MsgBox "Only numbers allowed!", vbOKOnly + vbCritical, "Title" tb_mtb.Value = "" End If End Sub Private Sub tb_fil_KeyUp(ByVal KeyCode As

VBA Excel - Working with multiple textboxes with the same code

限于喜欢 提交于 2021-02-04 16:38:05
问题 So I'm new to this area. I just want to ask if how can I minimize the use of the code below since I do have 13 textboxes with the same code. Is there a short way to do this? Here's the UserForm that I'm using -> Here's the code Private Sub tb_mtb_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Not IsNumeric(tb_mtb.Value) Then MsgBox "Only numbers allowed!", vbOKOnly + vbCritical, "Title" tb_mtb.Value = "" End If End Sub Private Sub tb_fil_KeyUp(ByVal KeyCode As

type-declaration character does not match declared data type

有些话、适合烂在心里 提交于 2021-02-04 16:25:26
问题 I keep getting this compile error based on the code below and I cannot figure it out for the life of me. Can you guys see what the problem is? It highlights the "p" when I go back to debug. Thanks, R Function EuroBin(S, K, T, rF, sigma, n, PutCall As String) dt = T / n: u = Exp(sigma * Sqr(dt)) d = 1 / u: p = (Exp(rF * dt) - d) / (u - d) EuroBin = 0 For i = 0 To n Select Case PutCall Case "Call": EuroBin = WorksheetFunction.Combin(n, i) * EuroBin + p^(i) * (1 - p) ^ (n - i) *

Refresh All Queries in Workbook

南笙酒味 提交于 2021-02-04 16:01:13
问题 This works for .xls books, but can it be altered for .xlsx workbooks as well? Or is their syntax that will work for both? Option Explicit Public Sub RefreshQueries() Dim wks As Worksheet Dim qt As QueryTable For Each wks In Worksheets For Each qt In wks.QueryTables qt.Refresh BackgroundQuery:=False Next qt Next wks Set qt = Nothing Set wks = Nothing End Sub EDIT -- So it seems my syntax does refresh .xlsx workbooks, but not queries that are from sql server. How can those be refreshed via VBA.

Check if value exists in range without looping

和自甴很熟 提交于 2021-02-04 15:54:08
问题 I'm used to python syntax where to check if 7 is in list1 you simply type 7 in list1 and it returns a boolean. How can I perform something like this in vba? I'm currently looping through a large range. I want to occasionally check if a value i'm looping over is in a different range. This could get much slower if I had to nest more loops into my loops. What's the fastest way to approach this problem? For i = 400 To 1 Step -1: 'doing other things 'here's some psuedo-code of what I want to do If

Shuffling a Set of Rows in VBA

若如初见. 提交于 2021-02-04 14:17:48
问题 I am new with VBA so I am having some problems sorting this out. I have a set of rows which I have to record a macro to shuffle ALL rows. That is, there must be no rows left unchanged after I run the macro. And the thing is, this set of values is not a single column. There are several columns which must be taken into account. Shuffling has to be made without changing the entire row, and the shuffle has to occur for all of the columns. A very simple example: Values before shuffle: A 1 B 2 C 3

Create new tab for each google search by selenium in excel VBA

别来无恙 提交于 2021-02-04 14:09:05
问题 I am trying to do google search based on some data in column A in Sheet1 .. and I need each cell content to be opened in new tab and do the search for that cell example: A1 has the word 'flower' so I expect to create a tab and navigate to google the do a search for that 'flower' then the next cell and so on and each search to be in a new tab Here's my try Sub Test() Dim bot As New ChromeDriver Dim Keys As New Keys bot.Get "https://www.google.com" 'search for items in column A bot