Click here to Skip to main content
15,885,309 members
Everything / VBA

VBA

VBA

Great Reads

by William Hey
Classical number theories
by bradyguy
An end to end view of how to integrate Jira REST API's with Excel.
by RB Starkey
How to create a tree-view control using an Access table and form.
by William Hey
Semi-Prime Ordered Sequences (Part 2) is the follow-on to “Exploring Computational Number Theory (Part 1)” and describes a process for ordering the semi-prime base sequences.

Latest Articles

by NewPast
Indent code, add line numbers, err handling, add number to words and more, expose a .NET library to Microsoft Word, Excel, Power Point macros writers and Access VBA code
by NewPast
Floating point numbers as approximates and understanding error happened when using single and double data types
by Patrice T
The Excel Tools I crafted to simplify my life as programmer
by Mirzakhmet Syzdykov
Development process in few steps with the help of scripting software

All Articles

Sort by Score

VBA 

12 Apr 2016 by bradyguy
An end to end view of how to integrate Jira REST API's with Excel.
16 Jul 2013 by RB Starkey
How to create a tree-view control using an Access table and form.
31 May 2016 by William Hey
Semi-Prime Ordered Sequences (Part 2) is the follow-on to “Exploring Computational Number Theory (Part 1)” and describes a process for ordering the semi-prime base sequences.
12 Jun 2017 by LukeCodes
This is a simple macro script to search and retrieve individual cells in an Excel document.
16 Jan 2016 by Glenn Lloyd
This is an alternative for "A Simple List Class for VBA Projects"
7 Sep 2018 by Clifford Nelson
This is a tip that has the code for selecting an Excel file and sheet for import into Microsoft Access. This includes the code required to browse for a file, and populate a ListBox with the sheets of the Excel Workbook, and the code to import an Excel spreadsheet.
6 Jul 2021 by VisualMonsters
Simple game "table football", you can easily create and play with your friends and family
26 Mar 2019 by Igor Krupitsky
This program will convert office, text and image files to PDFs.
31 Oct 2022 by Wayne Jin
A walkthrough to create a count down timer Add-in for Powerpoint
8 Mar 2012 by Torsten Tiedt
Avoid event spaghetti code when business logic becomes complex.
3 Mar 2012 by Andreas Gieriet
You may be looking for the Gestalt Approach as described in Dr. Dobbs Article of July 1988: Pattern Matching: the Gestalt Approach[^].Maybe, this[^] article helps too.CheersAndi
6 Mar 2012 by Sergey Alexandrovich Kryukov
Here is my idea:The algorithm should accept three things on input: to string to be compared and the meta-data. The meta-data would contain parameters for comparison: weight factors to be used, character sets, maybe even dictionaries; please see below on optionality. Basically, you would need...
12 Apr 2012 by Fredrik Bornander
Assuming a spread sheet when column A holds your A values, C holds your C values and B holds the formula (starting at row two), then the formula for row 2 can be written as;=IF(C2
4 Dec 2012 by Wendelius
If you use for example PDFSharp[^], you could follow this example: Combine Documents[^]
19 May 2015 by algor-AG
VBA: Excel / Word programmatically save document as PDF encrypted / password protected.
8 Nov 2015 by veen_rp
Why can't you set transparency to a picture in an MSOffice application? Well, you can use a clumsy work-around to create a shape and paste your picture from the clipboard. Here's the code to automate it from VBA.
9 Nov 2015 by veen_rp
A simple, step by step tutorial to set up an MS-Office Excel Ribbon, launch your own .NET applications from Excel and interact with the spreadsheet values.
16 Dec 2015 by maxitone
Use this if you're working in a fullscreen RDP session - for example - to see new e-mail or appointment alerts
26 May 2011 by Abhinav S
Len should be returning a numeric value - so you should not be comapring against '10' but rather 10.This line should look like sql = sql + "Where len([" + fld.name + "])
28 Jan 2012 by Dalek Dave
I am trying to upload a spreadsheet to my webspace via VBA.It isn't working.Am I missing something obvious?I have stepped through and it crashes at the end, going to the msgbox and showing a fail.I think the problem is at the HOSTNAME stage, but for the life of me I cannot see...
29 Nov 2013 by Sergey Vaselenko
Hello,You may use the following formula on a worksheet:=NOT(ISERROR(MATCH("*";$A$1:$A$10;0)))But, "~" must be specified as "~~". For example:=NOT(ISERROR(MATCH("~~";$A$1:$A$10;0)))VBA functions:Function MyMatch(ByVal lookup_value As Variant, ByVal lookup_range As Variant)...
24 Jun 2014 by Bhis
Back in 2008, I was doing some freelance work and had a chance to work on this MS Access Report project. The client dealt with employee benefits, claims, and payment reimbursements.
17 Jan 2015 by Liju Sankar
Read Loud Email Sender and Subject as soon as you received an email in OUTLOOK
22 Jul 2015 by Wendelius
Based on your code I'd say that the selection is lost when you set the borders. Because of that there's nothing to paste when you hit the PasteSpecial call.Instead of With Selection .Borders.LineStyle = xlContinuous ...
9 Oct 2015 by Gustav Brock
Generic VBA functions for all the normal rounding methods - of any value that VBA can handle.
27 Apr 2016 by F-ES Sitecore
Doubles are an approximation of the numbers, not the exact numbers so they shouldn't be used where precision is required as you'll get these kinds of issues.
27 Apr 2016 by phil.o
You are facing an issue with floating-point arithmetic precision.Please have a look at What Every Computer Scientist Should Know About Floating-Point Arithmetic[^][Edit] By the way, there exists an excellent article from John Simmons / outlaw programmer here on CP; it presents a way to...
17 May 2017 by Maciej Los
Assuming that you want to copy data from one sheet into another, when specific condition is meet (Level>1), you can achieve that in two ways: Using ADODB.Recordset[^] + Range.CopyFromRecordset method[^] This method is really fast! 'needs reference to Microsoft ActiveX Data Object Library x.x...
3 Feb 2020 by CHill60
You can use the Folders.Add method [^] method to create the folders either based on Now or on Outlook.MailItem.CreationDate (the latter might be useful if you want to retrospectively move stuff) If I've misunderstood, and it's a folder on your C: drive you want to create then you can use the...
2 Apr 2021 by Maciej Los
Try to use Range.ClearFormats method (Excel) | Microsoft Docs[^] With Worksheets("WB").Range("a1:z500") .ClearContents .ClearFormats .CopyFromRecordset rs End With
22 Feb 2022 by CHill60
Of the things you have allegedly tried...Range(RValue, Cells(RValue.Row, LastColumn).Column) gives a Type Mismatch error, assuming that LastColumn is a rangeRange(RValue:cells(RValue,LastCol)) just gives a compile error because of the colon : If...
1 Dec 2023 by Maciej Los
Couldn't it be better to re-write all macros from VBA to C#? Whatever you want to do with Excel data, you can do it in C#. Take a look at EPPlus library[^]. This library is powerful, elastic. You don't need to have an Office installed on your...
30 Dec 2023 by Mike-MadBadger
To learn the basics start with a really simple example and once you know how to make that work then you can start the more complex implementation you outlined above. There are lots of examples out there, here's once : Create a new Class Library...
14 Oct 2010 by E.F. Nijboer
You can check with ERRORLEVEL.IF ERRORLEVEL 1 GOTO LABEL1http://www.robvanderwoude.com/errorlevel.php[^]http://www.computerhope.com/if.htm[^]Good luck!
15 Feb 2011 by Andrew Brock
It is not related to your actual question, but it is a problem none the less.Double numbers can have decimal places, hence the following code will not work correctlyint calcgrade(double average, char& grade){ if (average
20 Feb 2011 by Steve L. Powell
Sorting worksheets in Excel using VBA
17 Jul 2011 by thatraja
I'm sure you mean this control ezVidCap Component by Ray Mercer (VB6)[^]BTW I found these in CPC# \ VB.NET Camera Communication Libraries[^]Webcam using DirectShow.NET[^]Versatile WebCam C# library[^]WebCam Fast Image Capture Service using WIA[^]
7 Oct 2011 by Sergey Alexandrovich Kryukov
What do you mean by the "difference" highly depends on how you define it, in particular, in XML schema uses and its mapping onto the "difference" file.First of all, you need to find difference not between files, but between logical structures of the XML. The same logical structure could be...
10 Oct 2011 by Richard MacCutchan
My suggestion would be to add a Auto_open VBA macro which offers the copyright notice as a dialog. The user then has the choice to click on Accept or Reject, and if not Accept the macro automatically closes the worksheet. Of course, this is not foolproof, but it is at least good enough to make...
12 Oct 2011 by CPallini
Instead of creating such object, you may use SHFileOperation function[^] for the purpose.
25 Nov 2011 by Maciej Los
You can't use something like this: "Lec" And False in the Select ... Case ... End Select statement.The correct statement is:Select Case optLect.Value Case True Select Case bMain Case Is = "Cat", "Lec" chkWkTemp.Value = True Case...
16 Mar 2012 by Sachin Chandanshive
Read / Write data from CSV to Excel
12 Apr 2012 by VJ Reddy
The Solution 1 given by Fredrik Bornander is very good.I want to add that, as observed from the pattern of values in columns A, C, the total of A+C is 2013, 2012, 2011 under each part in the consecutive three rows, except for row 3 in Part 2 and row 2 in Part 5. I think by following the...
13 May 2012 by Maciej Los
Just record macro!Let's say, your data are in column A.1) Start recording2) Select column A 3) Menu Data->Text As Columns4) Menu Data->Sort (by column A, B, C)5) For cell D1 add formula =A1 & "-" & B1 & "-" & C16) Fill down the formula7) Stop recording 8) ALT+F11 to open "VBA...
13 Aug 2012 by Sachin Chandanshive
Addin Containg Useful Macros & Easily Accessible From Ribbon Menu
15 Jul 2012 by Prasad_Kulkarni
You need to ask this question in proper forum to get quick and accurate guidelines as well as response.Article Writing[^] is the forum where this question belongs.And remember if you got any problems or issues while submitting your article then post your query on Site bugs and...
27 Jul 2012 by Kudredin
Making use of the User Defined Fields to help better organize emails, and keep track of informaiton
29 Aug 2012 by Maciej Los
First of all, read about MS Excel's objects[^], because Sheet object and Worksheet object is not the same.The best programming practice is to use code with context. To explain what i mean, do it:1) Open or create few MS Excel Workbooks,2) Activate first workbook and run this code:For i...
6 Dec 2012 by Adam R Harris
The path of least resistence to get this out of excel would be to copy and paste it into notepad then save its [something].vba. Then all you would need to do is just double click the vba file and your process would run. Outside of that you are going to have to pick a language, most likely...
1 Feb 2013 by PietersonK
Try MZ Tools it will have all necessory options needed for proper development.It also had a wonderful set of options like source code review , Statistics , Excel Documentation etc.., .
8 Jun 2013 by Member 10100038
I've made a serial number activation program which tries to find a *.txt file in my hard drive location C:\try. If it locates the file that it's name is the which contains the text from the serial number textbox. The problem is that on the 9th line I take this exception: AmbiguousMatchException...
16 Dec 2013 by Maciej Los
Please, read my comment first, then have a look here: WorksheetFunction.Sum[^].You need to pass Variant data type as input parameter. What it means to you? You need to pass Range[^] object!rec.Fields("TotalTime") = xlsSht.WorksheetFunction.Sum(xlsSht.Range("G13:G100"))It should...
18 Dec 2013 by Maciej Los
All you need to do is:Create table[^] to store file namesCREATE TABLE MyFiles (MyFile CHAR);Create new form[^] and drop on it ListBox controlDrop a Button control and create OnClick event Bind ListBox[^] with MyFiles tableGo to form module[^] and create new procedure...
1 May 2014 by Maciej Los
The error meassage says exactly what is wrong! The data from subquery are not related with main query and return more then 1 record!Using too many subqueries to produce columns could be the reason of application crash or performance issue at least.Redesign your query! Start with basics:...
9 Nov 2014 by Allen C. Copeland Jr
A guide on querying Excel ListObjects (Tables) by creating a state-machine out of synthesized objects that resemble a query language.
21 Mar 2015 by OriginalGriff
We do not condone, support or assist in the production of malicious code in any way, form or manner. This is a professional site for professional developers. If you want to know how to do such things, you need to visit a hacking site: but be sure to disable all firewalls and antivirus...
19 Apr 2015 by Bernster
How to use Excel conditional formatting features to simulate a progress bar in an Excel worksheet
16 Sep 2016 by axuno
Take this ready-to-use VBA module for MS-Outlook, that lets you export all mail messages selected in the current Outlook email browser to the file system.
9 Sep 2015 by Michael_Davies
Hello,You need a logical relationship between your condition, OR/AND etc.Str = "SELECT * From Items Where Material='" & ComboBox1.Text & "' AND Hardness='" & ComboBox2.Text & "'"Will work...
9 Oct 2015 by Maciej Los
If you want to insert formula into C2 cell, try this:Sheets(1).Range("C2").Formula = "=IF(ISERROR(MATCH(C" & cnt & ",C$2:C$" & lastrow & ",0)),'','Duplicate')"After that you can read the value (calculated via formula):retVal = Sheets(1).Range("C2").ValueNote: retval should be declared as...
12 Oct 2015 by OriginalGriff
To be honest, if you don't know either of them, then the first thing you need to do is learn one! You can't "work mostly in design mode" for VB or C# - they are general purpose languages and need you to be able to code in order to get the "design mode" stuff to actually do anything. And to do...
6 Nov 2015 by Dave Kreskowiak
Whatever that iItems object is it doesn't have a SendKeys method so you're getting that error.SendKeys is a stand-alone function. You just remove the iItems. part and you won't get that error any more.But, SendKeys is notoriously unreliable. You have no direct control over which control...
8 Dec 2015 by CHill60
You are using oCmd before it has been initialised. Try Set oCmd = New ADODB.Command oCmd.ActiveConnection = oCon oCmd.CommandType = adCmdStoredProc oCmd.CommandText = "spTest" oCmd.CommandTimeout = 0oCmd.Parameters.Append oCmd.CreateParameter("Periode1", adVarChar,...
9 Dec 2015 by Maciej Los
There's few possible reasons of 1004 run-time error, but the most important is: you cannot open pdf in Excel application! Conclusion: you cannot read from pdf file!On the first look:1) source file hasn't been opened,2) you did not set reference to a workbook (source file),3) sheet does...
23 Jan 2016 by Richard MacCutchan
Try some of outlook vba add cc - Google Search[^].
14 Apr 2016 by OriginalGriff
In conjunction with your other question: What does this mean? What will it do?[^]We can't explain every last detail of your homework to you: go and read your course notes, get a book and read it, whatever. You need to learn the basics and you clearly haven't.We arent here to do your...
27 Apr 2016 by bling
Use Decimal instead of Double.If you have to use Double, avoid equality / inequality comparisons. Pick a precision for your application. As an example of six decimals precision, replace "if (x 0.0)" with "if ( Abs(x)
5 May 2016 by CHill60
The code must be placed in the VBA for the sheet in question. If this is not running at all (which I'm guessing it's not as you haven't mentioned the errors) then you must have put it in- the wrong worksheet, or- the VBA sheet for ThisWorkBook, or- a VBA moduleWhen you put it in the...
5 May 2016 by Dave Kreskowiak
Your if condition is wrong. You cannot compare a range of columns to a string and get anything other than False. Also, your use of the keyword And is wrong. You must have a boolean expression on both sides of the And. It is never used to compare something to this And that.You have to look in...
14 Aug 2016 by User 11061201
Public Property menuName() As String Get Return Me._menuName End Get Set(value As String) 'WRONG _menuName = menuName Me._menuName = value End SetEnd Property
21 Sep 2016 by OriginalGriff
Simple: don't divide by zero.Which means: check your inputs.b = ActiveCell.ValueActiveCell.Offset(0, 1).Activatec = ActiveCell.ValueActiveCell.Offset(0, 1).Activatee = -1If b 0 Then e = (c / b) * 100End If
12 May 2017 by Jochen Arndt
It seems to be a limitation of SharePoint. A web research shows that entering wrong dates into a SharePoint form issues the error message Quote: You must specify a valid date within the range of 1/1/1900 and 12/31/8900 So you have to check the Excel date and limit it to the above range or ensure...
24 Oct 2017 by Maciej Los
A common difference between functions is that that function without $ returns variant, but with $ retruns string. Seems that using function with $ at the end is excuted bit faster. See: Dollar Sign ($) Functions[^] Note: When you work with MS Access, you have to be aware, that using function...
8 Nov 2017 by ZurdoDev
The easiest way to learn is to record a macro creating the pie chart manually. You can then go into the Macro Editor and see the code that was created.
19 Feb 2018 by OriginalGriff
Because it's a number - and unless the column is formatted as Text, or the number is preceded by a quote, Excel will treat it as a number. And numbers do not have leading zeros... Prefix the first 0 with a quote and Excel should treat it as text.
27 Mar 2018 by Maciej Los
I tested this: Option Explicit 'force variable declaration Sub InsertImageIntoSelection() 'variables Dim rng As Range, wsh As Worksheet Dim sFileName As String 'in case of error goto error handler On Error GoTo Err_InsertImageIntoSelection 'get selection ...
17 Apr 2019 by Christian Graus
I googled it GitHub - thinkingmik/FastFourierTransform: Compute the Fast Fourier Transform of sampled data[^]
24 Apr 2019 by Maciej Los
As we agreed with Caroline in the comments to the question, i would like to share my ways i've resolved such of issues... Method #1 - in case when unidentified signs/characters have been found in one or more modules: export and remove all modules (UserForms too) then compact and repair...
11 Nov 2019 by CHill60
That error means that the folder does not exist in that "area" of Outlook. If you debug your code and observe the contents of objNS you will realise that it contains the list of mailboxes, not the list of folders within a mailbox. You need to "point" to the appropriate mailbox first, then get...
11 Feb 2020 by MadMyche
All you need to do then is to change the connection string, removing the username/password attributes and replacing with trusted_connection. Here is the general format:"Provider=SQLOLEDB;Data Source=[Your DB Name];Trusted_connection=yes;"
29 Jun 2020 by Member 14874449
Walk-through and source code for an Excel VBA development workflow
28 Jan 2021 by Maciej Los
I'd avoid of using: Set re = CreateObject("VBScript.RegExp") I'd suggest to create Regex object via using reference to Microsoft VBScript Regular Expressions x.x.dll, where x.x is version number. Then, you'll be able to create object via...
8 Mar 2021 by W. García
VBA solution for CSV parsing problem
17 Jun 2021 by OriginalGriff
Since we can't see your code, have no idea what the error message is, or have any other information other than "it doesn't work" we can't help you fix this in any direct way. Remember that we can't see your screen, access your HDD, or read your...
26 Nov 2021 by Richard MacCutchan
VarString$ = "FF 01 01" That is what you are doing wrong. You are sending the ASCCI character string FF0101 instead of the actual hex (i.e. 8-bit) bytes FF0101. You need to use the VBA HEX function to get the correct values,...
19 Dec 2021 by CHill60
You are not going to learn how to do this from any video. My advice would be to use the Macro recording function in Excel - Make sure the Developer Tab is available in the Ribbon - Select Macros, Record Macro - Manually do the above steps -...
9 Jan 2022 by Richard MacCutchan
You can use VBA in a Word template to generate such a form. See word template vba - Google Search[^] for suggestions.
21 Jan 2022 by Richard MacCutchan
Rather than use a simple message box for these extra features, the Task Dialog - Win32 apps | Microsoft Docs[^] offers far more flexibility for your purpose. This probably also applies to your other question on this subject.
5 Feb 2022 by OriginalGriff
I'm not the only one who is getting fed up with your inability to work out what we need to know in order to help you: in this case as Dave has said VBA does not have a CopyMemory function so just repeating the code that calls it with no idea what...
13 Feb 2022 by Richard MacCutchan
PDF files have their own proprietary format, so you need to use one of the free libraries such as The Leading PDF Library for Developers | iText[^], NuGet Gallery | iTextSharp 5.5.13.2[^] etc.
13 Feb 2022 by Maciej Los
In addition to soultion 1 by Richard MacCutchan... No, you can't use ADO Stream to read pdf file and extract data! You can try to extract data from pdf via using Acrobat libraries. See: excel - Extract Data from PDF and Add to Worksheet - Stack...
14 Feb 2022 by Richard MacCutchan
1. Set hr = hDoc.body.getElementsByTagName("table table-striped table-bordered table-hover") 2. set hrr1 = hr.getElementsByTagName("th") 'error this line Line 1 returns a HTMLCollection - Web APIs | MDN[^] of all elements that have the named...
27 Feb 2022 by Joan M
When you forget to attach an invoice and your customer doesn't alert you... well, you start thinking about methods to prevent it from happening again.
4 Oct 2022 by junyaoxu
Step by step implementation of DCOM real time stock quote server with Yahoo financial API
6 Dec 2022 by Wayne Jin
Extend the function of Microsoft Office and Python
15 Apr 2023 by Dave Kreskowiak
It turns out that you CAN get some of the data you need, like the nonviewport height of the browser window and it's position on screen. It helps to go back and re-read the documenation I haven't read in the last decade. ...
24 Jul 2023 by OriginalGriff
Any code which includes the line "On Error Resume Next" should be taken out and ritually disassembled. It doesn't "get rid of errors" it hides them until they are too big to ignore - by which point you have probably done significant damage to...
6 Oct 2023 by Richard MacCutchan
A TreeView control does not contain columns, it is structured as a collection of parent-child nodes: see Excel VBA - The Treeview Control[^].