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
0
votes
1 answer

CreatePipe succeeds but does not generate a valid pair of handles

I am writing some VBA code, and I want to be able to spawn a child process and communicate with it via stdin/stdout. I found a description of how to do this in C/C++ here: Creating a Child Process with Redirected Input and Output I am using…
0
votes
0 answers

How to keep Number Format in a Variant data type

I have an APF variable store in columns apf_rev_info_col I set up its format number with 1 decimal number like this: Columns(apf_rev_info_col).NumberFormat = "0.0" Then I want to pick up unique value from this columns, using Application.Unique like…
0
votes
0 answers

method activate of object _worksheet failed

I want to display a specific sheet when I open the Excel file, but I am facing an error, please guide me to fix this error. Private Sub Workbook_Open() Worksheets("rahnama").Activate End Sub
0
votes
1 answer

Can't hide tab on subform

Can't hide tabs on subform. I have a form with a tab control. I have a cmd btn with the following code: Page16.Visible = False This works great. I have several cmd buttons as a work around for multi row bug in tabs. So, on this same form I have a…
Dennis
  • 33
  • 6
0
votes
1 answer

Apply macro to any sheet in the same workbook

I have a bunch of sheets in the same workbook and I want to be able to click a button and run a Macro in the sheet I clicked the Macro Button. This is one of my codes: Sub PromoCC() PromoCC Macro Sheets("Tipos de Proyecto").Select …
0
votes
1 answer

Extract Powerpoint chart Min and Max values

I am trying to create a VBA code which can help me open a presentation, go to each slide, check for a chart and then copy its min and max value in an excel sheet. I have a 40+ slides presentation with multiple chart and this code will help me to…
0
votes
1 answer

How to solve VBA - FormulaArray error 1004?

I am a new user of vba and I am experiencing this error 1004 "Unable to set the FormulaArray property of the Range class" by running the following code: Worksheets("Discriminatory_power").Range("G11").FormulaArray =…
0
votes
0 answers

Macro correctly running in the debugging, but when event is triggered it not running after the first event

I have a macro associated with a workbook to trigger some events when data is entered in column B. Along with this, there are two other modules related to this to for uploading excel when so many data are there and one module to protect and…
San Jay
  • 25
  • 7
0
votes
3 answers

Office 365 VBA Excel version 2208 from one day to the next "Automation error: The object invoked has disconnected from its clients" error

Without getting into the details of the code I have a VBA Excel program that shows a Userform at the user at some point in the code. This VBA Excel program is used for more then 10 years now without any problem. Suddenly from one day to another we…
Maxcit
  • 1
  • 2
0
votes
1 answer

How to auto size a row and Column in a specific sheet VBA

I have a debug button on a userform. The debug button needs to do 2 things: Auto Size row 17 Auto size Column X. I have tryied…
DVT
  • 3
  • 2
0
votes
0 answers

how to get worksheet name in VBA when user switches worksheet while editing a cell?

I need to get the name of the worksheet in which the user is currently editing cells. Activesheet.Name normally works, but if the user changes sheets while editing a cell I get problems. Assume that the code below is running for 'Sheet1': Private…
0
votes
0 answers

Declaring a function spitting out compile error saying it's outside of Sub

I've been trying to make a macro that pauses and waits until a key is pressed to resume. In multiple examples online I found this kind of function but when trying it myself, even testing it with the exact same code from the example, I get an error…
0
votes
1 answer

VBA Excel Form build from module, disappear after few 10/seconds

Looking for a more customizable MsgBox, I read some users that suggested to others with my same problem: build a form "on the fly"! Well. That's what I do. Unfortenately my code run, my form's shown, but suddently disappear.Only fews 10/secs, maybe…
Emanuele Tinari
  • 120
  • 1
  • 2
  • 10
0
votes
0 answers

Using excel VBA to connect to azure sql with active directory authentication

I'm trying to connect in excel vba to a azure sql database using adodb and AD Integration but none of the connection strings I am using seem to work. I am using ADODB.Connection in conjunction with the string below to connect to my sql server. I've…
0
votes
1 answer

VBA Can't close read-only workbook after updating from file

I want to update a read-only workbook from the file "Data.xlsx". I change the file in another application in a read-write workbook. When I try to close the read-only workbook after updating it, an error accours. This is my code: Option…
Abu Bakr
  • 3
  • 1