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
1
vote
2 answers

VBA excel count total number of folders (and file)

I have the following script. Want the number of folder, subfolders and files: Sub CountFiles(ByVal path1 As String) Dim fso As Object Dim subfolder As Object Dim file As Object Dim folder As Object Dim stetje As Long Set fso =…
user1509923
  • 193
  • 1
  • 3
  • 13
1
vote
3 answers

VBA Delete Row contains specific exact word

I want to delete rows from Excel if Column A contains "string1" as shown in the following table: A1 B1 string1 string2 string3 string4 string5 string6 string7 string8 I'm using the below code: Sub DeleteRows() Dim rng As Range …
mg g
  • 21
  • 4
1
vote
1 answer

Copying data from word table cell throws type mismatch error

Thanks for looking into this. I am trying to get values from word table into variable. For most part it works but for the last part I could not. Error is in this below line after search text is like "Interest Payment Dates (t)" retVal =…
Shri
  • 156
  • 11
1
vote
1 answer

Summing columns in VBA/excel in for loop

I'm trying to sum the contents of columns in Sheet1 that are 6 cells apart (i.e. the first is G19:G28, the second is M19:M28) using a for loop to define the column value. So, I want the sum of the G column, the sum of the M column, and so on, but…
Emily
  • 15
  • 3
1
vote
1 answer

How should I Use 1 code for same Objects in VBA Excel

Im working with a workbook with many sheets and im using a UserForm with more than 150 Combobox and arround 200 Labels. I want to set the charasteristic and design of the comboboxes in only one and i want to be applied in a lot of them, so i do not…
atallpa
  • 9
  • 1
1
vote
1 answer

Extract picture (.jpg or .png) from Access with Excel VBA

I would like to insert a picture (.jpg,.png) into an Excel sheet from an attachment' field from Access. My current code is something like this: Sub InsertPicFromAccessDB() Dim con As ADODB.Connection Dim rs As ADODB.Recordset Set…
Corneliu
  • 21
  • 6
1
vote
1 answer

Change the color of a shape inside a subgroup in VBA for Word

Hello I would like to change the color of a specific shape called "icon1" which is in a group called "Box1" but this "Box1" is in a group called "BigBox1" (So icon1 is in a subgroup). There is also other shapes and text boxes in the group "Box1"…
1
vote
1 answer

Access VBA and Smart Cards - what's the trick?

I'm trying to play with a smart card using Windows 10/Access 2016 and VBA, and I have come across just about every example I could possibly find of how to make this happen,…
Radio Doc
  • 379
  • 1
  • 4
  • 18
1
vote
2 answers

What is the proper way to add retry loop to VBA code

In the following code, we occasionally get collision errors. If it would wait a second and retry, it would go through. I want it to try once. If it fails, log the error and retry. If it fails 3 times, MsgBox to the user, give up and return. The only…
BWhite
  • 713
  • 1
  • 7
  • 24
1
vote
3 answers

Using VBA with Excel to Copy Item Data from One sheet to Another Sheet

I have a list of items in Sheet 1 (column A). Each item in sheet 1 has 5 cells of additional information (B thru F). Sheet 2 has some, even most of the same items at Sheet 1, but NOT ALL. I am trying to write a program that will start in Sheet 2,…
1
vote
1 answer

compatibility 32bit-excel and 64-bit excel (office 365)

I am not experienced at vba so thank you for understanding. I tested some old macros in office 365, previously I worked with excel 2016. I read that some macros might not work properly because of the Long variable declaration. - As I understand…
1
vote
1 answer

Advice about Arabic characters using VBA

I'm working to send Emails to each student containing ( student name and his marks ) from excel sheet as shown below Everything working fine, But when the student name is in Arabic char. the name shows as ( ???? ) as you can see below I changed…
Tariq
  • 101
  • 1
  • 1
  • 10
1
vote
1 answer

Outlook VBA script to save all attachments in an Inbox subfolder

I am trying to modify this VBA code to save all attachments from emails in an Inbox subfolder. Items populates with all the messages in this folder but the rest of the code is not working. I am trying to print out the item object to debug and that…
Austin
  • 11
  • 4
1
vote
2 answers

How to modify the appearance of UserForm Labels using Class Module?

I have this UserForm (Image 1) and I'm trying to apply some customization through Class Module. So, my first goal was to modify the label format when it was clicked (Image 2). So far so good, I've accomplished this through the Class Module…
Ninja
  • 15
  • 1
  • 6
1
vote
0 answers

VBA runtimes: msvbvm60.dll vs VBE7.DLL

I've read that VB6 used the msvbvm60.dll runtime library [1], and also that VBA and VB6 use the same runtime [2]. However I also remember reading that the current version of VBA in Office is VBA7, and if I look in the object browser I…
Greedo
  • 4,967
  • 2
  • 30
  • 78