Visual Basic for Applications (VBA) enables building user-defined functions (UDFs), automating processes and accessing Windows API and other low-level functionality through dynamic-link libraries (DLLs). VBA is closely related to Visual Basic and uses the Visual Basic Runtime Library, but it can normally only run code within a host application rather than as a standalone program. It can, however, be used to control one application from another via OLE Automation. VBA is built into most Microsoft Office applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

I am using MS Access 2016. I have an unbound main form with a bound subform.
On the Subform I have a True/False control (Whether a customer is active or inactive).
I want the default view to NOT include Inactive customers but have a tick box that will then include inactive customers.
I have used me.filter before bust I think I am having a problem with the True/False field.
Any help greatly appreciated.
Free Tool: SSL Checker
LVL 12
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Dear Experts:

below macro (Courtesy of MS Word 'Sage' Graham Skan) applies a user-defined paragraph style to the table cell that is located on the intersection of Row 4 and Column 2 (see line 10).

Could somebody please tweak this code due to a new requirement. The requirement is as follows:

Apply the heading Style "MyParaStyle" to the first paragraph of table cell (1,1), i.e. table cell (1,1) contains several paragraphs and only the first one should get the user-defined paragraph style applied.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub ApplyStyle()
    Dim tbl As Table
     If MsgBox("Would you like to apply the 'MyParaStyle' to the item name?" & vbCrLf & vbCrLf & _
     "This will be the basis for the Adobe Acrobat bookmarks!", vbQuestion + vbYesNo, "Apply Style to Product Name") = vbNo Then
        Exit Sub
        End If
    For Each tbl In ActiveDocument.Tables
        tbl.Cell(4, 2).Range.Style = "MyParaStyle"
    Next tbl
End Sub

Open in new window

Can you please explain this vlookup formula in column AN?
my data are in coloumn B and coloumn C
what I want is if data in coloumn B and C are equal  to each other  then fine
and if the data is not equal to each other then erase all the data in this sheet(completely erase the sheet,clear all the data in this sheet make this sheet blank)
need identify the pairs that  appear more than one

in ddbro 3 weeks range

here the file
I tried to create a table name Apps in the Movies database but don't know where it goes. Can you please help me out?
copy from sheet1 and paste to sheet2
this yellow colour I have putted it is just for understanding  purpose, in this yellow colour I have data
I have to copy paste this by vba
kindly see the attachment
what I want is to copy data from book1 sheet2  this part and paste to  to book2 sheet2 and save book2 excel file and close book2 excel file
I have highlighted this in yellow colour, this is just for understanding, in this yellow part I have data no yellow colour
I want to do this only by vba
kindly see book2 sheet2  
kindly see book1 sheet2

I have a LibreOffice Calcs document, and with VBA, from a workshet, I would like to:
- Retrieve the used range of the worksheet.
- Iterate over cells in that used range.

Here is what I have done so far:
Dim openOffice As Object
Set openOffice = CreateObject("com.sun.star.ServiceManager")

Dim starDesktop As Object
Set starDesktop = openOffice.createInstance("com.sun.star.frame.Desktop")

Dim args(0) As Object
Set args(0) = openOffice.Bridge_Construct("com.sun.star.beans.PropertyValue")
args(0).name = "Hidden"
args(0).value = True

Dim doc As Object
Set doc = starDesktop.loadComponent.FromUrl("file://c:/temp/myDoc.ods", "_blank", 0, args)

Dim ws As Object
ws = doc.sheets().getByName("Sheet1")

    '// used range ??????????

Open in new window

The used range can be anywhere in the worksheet (doesn't necessary start with A1 cell).
There r files that are saved in binary format  in the desktop
1)Day(saved in this name in the desktop)
2)Night(saved in this name in the desktop)
what i want is to copy all the data from sheet7 from night file and paste all the data to day file in sheet3
and save the data in day file and close all the workbooks by vba
The 14th Annual Expert Award Winners
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

I am working in Access VBA. I have two fields on a form. One is for Architect Firm and the other for Architect. The architect combobox needs to be filtered on Architect.FirmID so that only Architects from the selected firm are in the list. I am using [Screen].[ActiveControl].[Parent]![cmbArchitectFirm] as a criteria in the RowSource of cmbArchitect. It works great to filter it, but only after a record has been selected in the Architect Firm combobox, because the AfterUpdate event on cmbArchitectFirm has Me!cmbArchitect.Requery. Before I select the architect firm, the architect field is blank even if the firm and architect fields have values. I have tried putting Me!cmbArchitect.Requery in different opening events on the subform with no luck.
There are two forms where I am seeing this behavior. Both are datasheet subforms. I use the same controls in two form views where the form is primary. There I use [Screen].[ActiveForm]![cmbArchitectFirm] and it works great.
This is something I have been fighting off and on for several days, trying to figure out the best way to create this filter. If I have to use the actual form names to make this happen I will have to make several copies of my subforms so that every form will have it's own dedicated subform, which I would prefer not to do.
Any help would be greatly appreciated!!!
Need to find last vbFriday vba
If there is unhighlighted   data after the highlighted cell in a row then we have to clear all the data from start  till highlighted cell and paste the unhighlighted data from start in the row
and if there is no data after the highlighted cell in a row then simply copy and paste that row don’t do anything with that row
I have an Access (2016) database that used to work when I clicked on a button it would export the data to an Excel spreadsheet. I created the commands in Access's VBA (I am not a VBA programmer) however now when I try to run (click on the button), I get the following error "Compile error: Can't find project or library. Here is the VBA code that I am using:

strSQL = "SELECT * FROM " & "Table_ExpenseReport" & " WHERE " & "[ID] = " & ID & ";"

It is showing that the error is on the ID part. I want this to pull the data in the ID field (cell) in the Access database and keep it as the rest of the command sends that ID's data to the Excel spreadsheet and only that ID's data. Can someone help me? I am more than happy to attach screenshots, etc. to make this work again.
Using VBA in Outlook

Is there a way to add a "Browse" button in an Input Box?
A command button on my spreadsheet should hide/un-hide specified columns (in VBA code).    Please see attached XLS with VBA code (currently not working) and specific details as to what I would like to accomplish.

I'd welcome your feedback.   Thank you!

Using VBA in an Outlook Macro:

I am trying to BOLD text in a Input Box: "Please enter:" & vbLf & vbLf & "file_Name.csv"

The part I want to bold is the File_Name.csv so that is sticks out when the Input Box pops up.

I'm having trouble writing this code and getting it to run. It will not run at this point.

What I'm trying to do is have an email auto-send (I do not want to have to click run the macro every time) any time a cell value in column C changes to "POOR".

This is the code I have

Option Compare Text

Private Sub Worksheet_Change(ByVal Target As Range)

Dim OutApp As Object
    Dim OutMail As Object
    Dim strto As String, strcc As String, strbcc As String
    Dim strsub As String, strbody As String
    Dim myRange As Range
    Dim Cell As Range
    Dim row As Integer
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
     Set myRange = Range("A2:B7")

    strto = "cweatherford@txtav.com"
    strcc = ""
    strbcc = ""
    strsub = "Send Emails to Parents"
    strbody = "Students with poor performance and grade received:" & vbCrLf & vbCrLf
      row = 2
    For Each Cell In myRange
        row = row + 1

  If Not Intersect(Target, Cells(row, "C")) Is Nothing Then
        If Cells(row, "C").Value = "POOR" Then
          strbody = strbody & Cells(row, "A").Value & " " & Cells(row, "B").Value & vbCrLf
        End If
     Next Cell
     strbody = strbody & vbCrLf & "Please send emails to parents."
    With OutMail
        .To = strto
        .CC = strcc
        .BCC = strbcc
        .Subject = strsub
        .Body = strbody
Free Tool: ZipGrep
LVL 12
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

I’m trying to find vba to transfer an Excel file of my choosing from Windows Explorer into an existing table in Access without opening the Excel file.

I would like this to be attached to a button's on click event in Access.

I've only found code to open a folder but the file is opened when clicked and also one that only shows the folders and not the files within the folder.  Any help would be appreciated.
I have a database that runs an import of one CSV file and two xls files every day. I had set up fail-safes within the code to make sure that no blank files were imported, but recently discovered that this had caused some problems.

If DCount("*", "Table", "[Field]=Format('" & Activity_Date & "', 'Short Date')") = 0 Then
    MsgBox "Import brought over Zero files for Date imported. Please confirm this is accurate", vbYesNo, "Zero Import"
    If LResponse = vbNo Then
        Exit Sub
    ElseIf LResponse = vbYes Then

Above is the code that I created. Even if there is data in the table that is being searched, the database instead jumps to the Message Box line and then takes me to the bottom of the code that ends the import prematurely. So far, the only way that I've found to allow the import to go through completely is to turn off this section of the code completely. However, that means that there is no fail-safe in place if the import tries to bring in an empty CSV file. If there is any way to set this up, or maybe an easier way to check for blank CSV files, that would be greatly appreciated.
I had this question after viewing Environ("USERNAME").

I want to store username and date/Time stamp in each record, for 3 tables.

I am using below same codes for three forms ( BeforUpdate Event)

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me!updateBy = Environ("username")
Me!updateTime = Now()
End Sub

However, in one form, the [updateBy] field and [updateTime] fields are saved, but in two forms its not saved.
Its shows error as Field updateby is not found..
What can be the cause ?
Would appreciate help.
Thanks in advance.
Kamlesh Jain
comparing tables and highlighting the equal cells by vba
Kindly see the sample file
copy highlighted cell from sheet1 and sheet2 and paste the highlighted cell to sheet3
while pasting highlighted cell add  sheet1 highlighted cell  and sheet2 highlighted cell in sheet3
kindly see the sample file
Within Excel VBA I wish to retrieve the maximum date found when multiple matches are found.   I tried the VBA Function Vlookup and a sort, but it does not work,,,

Lookup Value         Date (Expected returned Value)
Conoco                     01/26/1965
Amoco                     01/26/2005

Table Array
Conoco  01/01/1900
Conoco  01/26/1965
Shell       07/01/1995
Shell      01/26/2005


Visual Basic for Applications (VBA) enables building user-defined functions (UDFs), automating processes and accessing Windows API and other low-level functionality through dynamic-link libraries (DLLs). VBA is closely related to Visual Basic and uses the Visual Basic Runtime Library, but it can normally only run code within a host application rather than as a standalone program. It can, however, be used to control one application from another via OLE Automation. VBA is built into most Microsoft Office applications.