Questions tagged [vba7]

Visual Basic for Applications (VBA) is an event-driven, object-oriented programming language for writing macros, used for the MS Office suite as well as other applications. VBA is not equivalent to VBA6, VBA7, VB.NET, or VBS. If your question is specifically about programming any MS Office application, also use the appropriate tag: [excel], [ms-access], [ms-word], [outlook], [powerpoint] or [ms-project].

Visual Basic for Applications (VBA) is an event-driven programming language which was first introduced by Microsoft in 1993 to give Excel 5.0 a more robust object-oriented language for writing macros and automating the use of Excel. The language and its runtime quickly matured and began being used in products beyond Microsoft Office applications.

Differences between VBA 6.0 and VBA 7.0?

There's not a whole lot that has changed between VBA6 and VBA7. VBA7 was introduced to support 64-bit versions of both Office and Windows (see below on what those differences are). Here are the key changes:

  1. 64-bit support, primarily for API calls. This is both used to make your code work with your OS/Office version as well as others' (i.e. someone on Office 2003/WinXP)

    • If you are on a 64-bit version of Windows, but are on a 32-bit version of Office, you can declare API calls like below. .

      #If Win64 Then
          Declare PtrSafe Function GetTickCount64 Lib "kernel32"() As LongLong
      #Else
          Declare PtrSafe Function GetTickCount Lib "kernel32" () As Long
      #End If
    • If you are on a 64-bit version of Windows, and are on a 64-bit version of Office, you can declare API calls like: .

      #If VBA7 Then
         Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
             ByVal lpClassName As String, _
             ByVal lpWindowName As String) As LongPtr
       #Else
         Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _
             lpClassName As String, ByVal lpWindowName As String) As Long
      #End If
  2. To support this, there are:

    • Three new keywords (2 data types and 1 modifier): LongPtr, LongLong and PtrSafe

    • One new function: CLngLng() (i.e. Int64)

    • The new compilation constants as used above: VBA7 and Win64

Reference

Differences between VBA 6.0 and VBA 7.0

308 questions
-2
votes
1 answer

Move to next file in a folder VBA

I am trying to loop all the files in a folder, while trying to loop it is not looping instead it is selecting the same file and if I tried with wild card Dir becomes null character. I need to check all the excel files and if folder exist, I need to…
Itzme ram
  • 13
  • 3
-2
votes
1 answer

Excel VBA code to disable four buttons in order of priority

There are four buttons to click to take four sample weights. The buttons are B1,B2,B3 and B4. B1 must be clicked first, followed by B2, then B3 and lastly B4 in that order of priority. I want to write an excel VBA code for below senario: (1)B2, B3…
Atobseg
  • 1
  • 2
-2
votes
1 answer

Loop-ing through folders based on DATE (taking remaining dates) VBA

I wrote a code in VBA that takes data from a lot of individual files from separate daily folders (e.g. 2021-10-09 is a folder). The way it works now is like this: I select through some inputboxes the day and month and then my code runs on that…
-2
votes
2 answers

VBA: "Run-time error '457':This key is already associated with an element of this collection"

I am having trouble writing a macro for comparing multiple columns in multiple sheets (of same excel file). I wrote few but they were taking so long that excel was crashing. Let's say I have 4 sheets in one same file. Sheet1 with two columns (B and…
Elmar
  • 1
  • 3
-2
votes
1 answer

How to insert dynamically an horizontal line in a graph associated with the last value of a certain range of values

I am trying to automatically insert a horizontal line on a chart that receives 5 series of data from a table. With each new day, I add another row of values to that table. And I wanted to insert in the graph obtained from these 5 series, a…
ajsor
  • 5
  • 3
-2
votes
1 answer

button different from Module?

Private Sub CommandButton1_Click() Dim nbp As Long Dim i As Long Dim p As Long Dim FV As Variant Dim CS As Variant Dim K As Variant Dim iFV As Integer Dim iCS As Double If Range("B9") = "Semi-Annual" Then p = DateDiff("yyyy",…
1 2 3
20
21