![]() |
LinkedIn is one of the most influential social media networks. LinkedIn enables you to network with similar industry people, and professional organizations in your industry as well as others. You can invite anyone to connect and accept their invitations to connect with you. If you are a company/professional and want to connect a large number of profiles then manual sending LinkedIn Connect requests is a time-consuming task. In this blog, we will learn how we can create a Selenium script in VBA to send automatic Connect requests by already saved LinkedIn profile URL in MS Excel. First, you need to install Selenium for VBA. Step 1: Create MS Excel Macro-Enable file
![]()
Step 2: Setup VBA Editor for script
![]()
Step 3: Create Open Browser Script
Option Explicit ' Global Variables Dim driver As New WebDriver Dim By As New Selenium.By Sub OpenBrowser() On Error GoTo ErrorHandler If MsgBox("Are you sure to open Chrome Browser?", vbQuestion + vbYesNo) = vbNo Then Exit Sub driver.AddArgument "user-data-dir=" & ActiveWorkbook.Path & "\vbauserdata" driver.Start "Chrome" driver.Get "https://www.linkedin.com" Exit Sub ErrorHandler: MsgBox Err.Description, vbCritical End Sub Step 4: Create Send Connect Request Script
Sub ConnectProfile() On Error GoTo ErrorHandler Dim i As Integer, startRow As Integer, endRow As Integer Dim linkedInURL As String '''Our profile will start form row 2 and can read till 5000 rows or no profile found startRow = 2 endRow = 5000 Application.DisplayStatusBar = True '''Read Excel file For i = startRow To endRow linkedInURL = "" linkedInURL = Sheets("ProfileURL").Range("B" & i).Value ''If there is no LinkedIn URL then exit script If InStr(linkedInURL, "linkedin") = 0 Then Exit For End If Application.StatusBar = "Running: " & linkedInURL ' Open current profile driver.Get linkedInURL ' HTML Code is taken by Inspecting element If driver.IsElementPresent(By.XPath("//div[@class='pvs-profile-actions ']//button[contains(@aria-label, 'Invite ')]")) = True Then Set connectButton = driver.FindElementByXPath("//div[@class='pvs-profile-actions ']//button[contains(@aria-label, 'Invite ')]") driver.ExecuteScript "arguments[0].click();", connectButton '' Send Connect Request Set sendButton = driver.FindElementByXPath("//button[@aria-label='Send now']") driver.ExecuteScript "arguments[0].click();", sendButton Application.Wait Now + #12:00:02 AM# Sheets("ProfileURL").Range("C" & i).Value = "Connect Request Sent" End If Next i Application.StatusBar = "" MsgBox "Script is completed successfully!", vbInformation Exit Sub ErrorHandler: MsgBox Err.Description, vbCritical Application.StatusBar = "" End Sub Step 4: Assign Macros to Buttons
Step 5: Running Script
|
Reffered: https://www.geeksforgeeks.org
Excel |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |