Open an Excel file from SharePoint site

Try this code to pick a file from a SharePoint site: Dim SummaryWB As Workbook Dim vrtSelectedItem As Variant With Application.FileDialog(msoFileDialogOpen) .InitialFileName = “https://sharepoint.com/team/folder” & “\” .AllowMultiSelect = False .Show For Each vrtSelectedItem In .SelectedItems Set SummaryWB = Workbooks.Open(vrtSelectedItem) Next End With If SummaryWB Is Nothing then Exit Sub If I remember correctly, the Microsoft … Read more

Find last row in range

There are mulitple results and methods when searching for the LastRow (in Column B). When using Cells(.Rows.Count, “B”).End(xlUp).Row you will get the last row with data in Column B (it ignores rows with spaces, and goes all the way down). When using: With wbshtSelect.Range(“B10”).CurrentRegion LR_wbSelectNew = .Rows(.Rows.Count).Row End With You are searching for the last … Read more

Excel error 1004 “Unable to get …. property of WorksheetFunction class” appearing inconsistently

This error occurs often when any argument passed to the worksheet function is not of the correct type or simply doesn’t make sense. For example, I’ve had this problem when calling WorksheetFunction.Asin with an argument bigger than 1. In your case, I’d guess currentCell.Value is a non-numeric value or one not according to your region … Read more

Removing special characters VBA Excel

What do you consider “special” characters, just simple punctuation? You should be able to use the Replace function: Replace(“p.k”,”.”,” “). Sub Test() Dim myString as String Dim newString as String myString = “p.k” newString = replace(myString, “.”, ” “) MsgBox newString End Sub If you have several characters, you can do this in a custom … Read more

VBScript – How to make program wait until process has finished?

You need to tell the run to wait until the process is finished. Something like: const DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0, WaitUntilFinished = true set oShell = WScript.CreateObject(“WScript.Shell”) command = “cmd /c C:\windows\system32\wscript.exe <path>\myScript.vbs ” & args oShell.Run command, DontShowWindow, WaitUntilFinished In the script itself, start Excel like so. While debugging … Read more