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
0 answers

Why does my embedded chart cause Excel to crash if I don't open VBA first?

I have an embedded chart on a protected Excel sheet that I would like to process chart events on (MouseMove and MouseDown), but Excel crashes when I click on the chart unless I first open the VBA editor. If I don't open VBA and click on the chart,…
matt7
  • 11
  • 3
1
vote
2 answers

VBA only runs if I open the editor or run the script manually

I wrote a small piece of code for Outlook 2016 that takes emails from my Inbox and Sent Items folders and moves them to an archive folder, but even if I use the Application_Startup or Application_Quit methods, the script only works if I open the…
Solrack
  • 11
  • 1
1
vote
1 answer

Sort data in VBA doesn't execute

I tried to copy the worksheet RLDSht in the first workbook in to my 2nd workbook. Then it's called USSht worksheet. I want to sort data in this USSht but it doesn't execute even when I Activate the worksheet. Here is the code: Public WorkbookName As…
1
vote
2 answers

Difference between count and end(xlup)

I want to understand the difference between count and end(xlup) The purpose of both the expressions is to count number of cells with values in it! Then why are we using it together in the following code below: Lastrowindex = cells(rows.count, "A").…
1
vote
0 answers

I want to copy filtered cell from excel VBA

I'm just learning VBA and I wanted to know cause i made some code for copying down from excel sheet that have been filtered but are still not able to do it Sub Compile_SKU_Inventory_Summary() Application.ScreenUpdating = False …
1
vote
2 answers

How to Find how many Letters does a Text Box's value has in VBA?

I Wish there is a way to get the amount of the characters of a Text Box Value so I can limit it to be the amount that I wanted. so like when someone entered 134131323 as the Year of Date, I can limit it to 4 characters. Also I the programming…
Aydiniyom
  • 13
  • 4
1
vote
0 answers

Data refresh error using VBA code to refresh Excel connection

I created a connection in Excel using SQL query, and I have a dynamic query in my Excel cell. This will be dynamic and will be updated based on the slicer options I created. I want to run the query based on the dynamic query refers from Excel…
1
vote
1 answer

ODBC--Call failed on RecordSet

Hellow i need your help i have a access database software, so i decided to migrate into sql server by sql migration assistant after that i tested my linked tabled to my access Graphical user, but fails some of code it seems doesn't applied in that…
1
vote
1 answer

Word VBA Text Box on first page not anchoring to table in document with a table and textbox each page

I have the following Word VBA code which creates a word document, puts a table on each page, and anchors a textbox to each table. On pages 2-6 the textboxes are correctly anchored and appear underneath the table. But on page 1 the table is not…
1
vote
1 answer

VBA Type Mismatch Issue

Sub Delete_Specific_Columns() Dim sh As Worksheet Set sh = ActiveSheet sh.Columns("B:D,I:AZ,BC:BJ,BO:EQ").Delete End Sub Keep getting a type mismatch error.
1
vote
2 answers

Index Match VBA Formula Not Updating to Correct Row

My code runs but MATCH('Worksheets1'!$D2, is not changing or updating based on the the row it is at. For example if my worksheet contains 2000 rows to be index matched the formula will still just contain MATCH('Worksheets1'!$D2 as the cell it is…
1
vote
2 answers

Convert ppt to pdf and protect the file

The below is the line of code I'm using it currently which converts ppt to pdf, however I want to protect pdf , Is there any possibility PowerPointapp.ActivePresentation.SaveAs path & pdffileNm & ".pdf", 32
NishuSruj
  • 41
  • 4
1
vote
1 answer

Split cell value and keep formatting on new workbook

I am attempting to select a cell filled with text and split/parse the text onto individual rows in a new workbook while maintaining the source font format (i.e. bold text). In the code below I am attempting to perform my split on the row cell value,…
AnotherDay
  • 11
  • 1
1
vote
0 answers

Getting an error message when trying to "Split Database"

I am trying to split my dbs, but keep getting an error: I don't have an append query. I have gone through every single object in the database, modules, tables, name it - there is no single "INSERT INTO" statement that I can see. I searched hidden…
Robert ZG
  • 23
  • 4
1
vote
2 answers

How to run a loop through filtered list in excel

i am trying to run this loop/code through a filtered list in excel where the row numbers are not in sequence eg the first row that meets the filtered criteria could be row 3, followed by row 7 then row 34 for instance. this is my current code which…
Tom Bob
  • 11
  • 1
1
2
3
20 21