Help identifying what each line of code does (Short code!)

sanantonio

Board Regular
Joined
Oct 26, 2021
Messages
124
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Apologies in advance some of the code is in Portuguese as this is a macro borrowed from my colleagues in one of our Portuguese offices. Folha = Sheet. I can't decipher what the "lr" or "i" would be in English though?

VBA Code:
Sub SendKeysWFM()

Dim lr As Long
Dim i As Long
  
lr = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row



For i = ActiveCell.Row To lr

'Folha5.Cells(i, 2).Copy


Application.WindowState = xlMinimized
Application.SendKeys ActiveSheet.Cells(i, ActiveCell.Column), True
Application.SendKeys ("~"), True


Next i
Application.SendKeys "{NUMLOCK}"
End Sub

My Portuguese colleagues are using this excel macro to load data into a browser based piece of software that is unique to our business. We have the same piece of software, albeit in English(!). But when I run the macro all it seems to do is minimize my excel (The line Application.WindowState = xlMinimized presumably) but nothing else seems to happen.

Can anyone identify what each line of code is actually doing? I'm used to coding vba to SAP and there's a lot of code involved that lets you know when the excel is talking to SAP, I expected something similar here but it seems very very basic.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You have to send the keys somewhere where are the keys going?? It's just minimizing the excel software. You can try this code how to send keys to other programs. Open chrome and run this code
VBA Code:
Sub Copy_102()
        
          AppActivate "Chrome"
          Application.SendKeys "%d"
         Application.Wait Now + TimeValue("00:00:01")
         Application.SendKeys "Weather~"
        
        
End Sub
 
Upvote 0
Ah okay, so "Send Keys" is the command that can send things like text or a value in a cell(s).

So in your example what is the "%d" doing?

and in my example what is the "~" and "{Numlock}" doing?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top